Results 1 to 6 of 6
- 02-14-2011, 04:42 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
unreported exception java.lang.Exception; must be caught or declared to be thrown
help guys.. i alway get this.. i'm new to java and exception handling
and been following a guide
but this error shows..
heres part of my code:
public class singleTwo extends Canvas implements CommandListener {
/**
* constructor
*/
Random rnd = new Random();
String who;
int totalP, totalC, score, stage, ctr;
int PlayerTemp1, PlayerTemp2, PlayerTemp3,OppTemp1, OppTemp2, OppTemp3;
int playerVal1, playerVal2, playerVal3, oppVal1, oppVal2,oppVal3;
Image playerFirst, playerSecond, playerDraw, oppFirst, oppSecond, oppDraw = null;
Graphics g;
Image c1 = Image.createImage("/images/club_A.png");
Image c2 = Image.createImage("/images/club_2.png");
Image c3 = Image.createImage("/images/club_3.png");
Image c4 = Image.createImage("/images/club_4.png");
Image c5 = Image.createImage("/images/club_5.png");
Image c6 = Image.createImage("/images/club_6.png");
Image c7 = Image.createImage("/images/club_7.png");
Image c8 = Image.createImage("/images/club_8.png");
Image c9 = Image.createImage("/images/club_9.png");
Image c10 = Image.createImage("/images/club_10.png");
Image cj = Image.createImage("/images/club_j.png");
Image cq = Image.createImage("/images/club_q.png");
Image ck = Image.createImage("/images/club_k.png");
Image d1 = Image.createImage("/images/diamond_A.png");
Image d2 = Image.createImage("/images/diamond_2.png");
Image d3 = Image.createImage("/images/diamond_3.png");
Image d4 = Image.createImage("/images/diamond_4.png");
Image d5 = Image.createImage("/images/diamond_5.png");
Image d6 = Image.createImage("/images/diamond_6.png");
Image d7 = Image.createImage("/images/diamond_7.png");
Image d8 = Image.createImage("/images/diamond_8.png");
Image d9 = Image.createImage("/images/diamond_9.png");
Image d10 = Image.createImage("/images/diamond_10.png");
Image dj = Image.createImage("/images/diamond_j.png");
Image dq = Image.createImage("/images/diamond_q.png");
Image dk = Image.createImage("/images/diamond_k.png");
public void singleTwo() throws Exception {
setFullScreenMode(true);
try {
// Set up this canvas to listen to command events
setCommandListener(this);
// Add the Exit command
addCommand(new Command("Exit", Command.EXIT, 1));
} catch(Exception e) {
e.printStackTrace();
}
}
i don't get it..the error disappeared after I tried to put it inside try{} but then the variables of the image needed for a code outside of try{} is then hidden..
thanks guys
- 02-14-2011, 04:44 PM #2
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
oh by the way..the error is pertaining to the images having unreported IOException..
- 02-14-2011, 05:15 PM #3
It's pretty self-explanatory: the line that causes the error can throw an IOException that you aren't catching, and the method that contains that line isn't declared to throw it. Do one of those things.
As for your problem with variable scope, you can declare the variables outside of the try.How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 02-14-2011, 05:42 PM #4
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
thanks kevin..i think that fixed it..but then..a new error occured..
unreported exception java.lang.Exception; must be caught or declared to be thrown
singleTwo = new singleTwo()
i know I should be trying to find the answer on my own now..but i really need help now..
thanks again
- 02-14-2011, 05:56 PM #5
It's the same deal- you're calling a method (presumably a constructor) that throws an Exception. You have to catch it, or throw the exception yourself.
If you want more help, I'd recommend providing an SSCCE that demonstrates the problem in as few lines as possible. You should probably also be more mindful of naming conventions- classes (and constructors) are capitalized, constructors do not have return types, and methods and variables are lowercase. Also, don't forget the code tags next time.How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 02-14-2011, 11:39 PM #6
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
Similar Threads
-
After catching the exception thrown
By scoobyrox in forum New To JavaReplies: 2Last Post: 09-05-2010, 02:29 PM -
Execution stuck at ObjectInputStream .readObject() with NO Exception thrown.JAVA BUG?
By r00tb33r in forum NetworkingReplies: 2Last Post: 06-01-2010, 02:58 AM -
Unreported exception java.sql.SQLException
By javamula in forum AWT / SwingReplies: 4Last Post: 09-29-2009, 02:32 PM -
Error: unreported exception java.io.IOException; ??
By jonsamwell in forum New To JavaReplies: 5Last Post: 08-24-2008, 04:11 AM -
Which exception is thrown.....
By money123 in forum New To JavaReplies: 1Last Post: 07-30-2007, 03:41 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks