![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Apr 2005
Posts: 3
Rep Power: 0
![]() |
exception handling
Here's the basic structure of my program
import stuff;
-----------------------------------------------
public class MapImage extends JFrame {
public MapImage()
{
super( "Mapped Image" );
setSize( 400, 165 );
show();
}
-----------------------------------------------
public void paint( Graphics g )
{
}
-----------------------------------------------
public static void main( String args[] )
{
MapImage app = new MapImage();
app.addWindowListener(
new WindowAdapter() {
public void windowClosing( WindowEvent e )
{
System.exit( 0 );
}
}
);
}
}The second method, public void paint, is the problem. I've left it blank because it's fairly long but I'll bring up the important parts here. First I open a file for input. File inputFile = new File( "map.gz" ); FileInputStream in = new FileInputStream( inputFile ); Then I read the first three byte values of the file and use them to set the color. g.setColor( new Color( c[0], c[1], c[2] ) ); I have a pixel drawn on the screen. g.drawLine( x,y,x,y ); Then I read the next three bytes of the file to get the next color and print the next pixel untill the entire file has been read. I'm left with a graphical representation of the file where each pixel represents three bytes. Then in.close(); But when I try to compile it I get these: unreported exception java.io.FileNotFoundException unreported exception java.io.IOException Where do I need to type in the "throws IOException" statement in order to fix this? I've tried it at the end of all three methods but still get the same problem. |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
|
put the code where your opening the file into a try statement, like this.
try {
File inputFile = new File( "map.gz" );
FileInputStream in = new FileInputStream( inputFile );
} catch(Exception e) {
System.out.println(e);
System.exit(1);
} |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Apr 2005
Posts: 3
Rep Power: 0
![]() |
Thanks. It worked.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|