Computer Science Canada Java exception.. why? |
Author: | ICS_hard [ Sat Jan 05, 2008 6:55 pm ] |
Post subject: | Java exception.. why? |
why does the code above give me an exception. NumberFormatException: For input string: "patrick.bmp" i have used alll kinds of methods to resolve it. i even tried -trial and error- nothig seems to work. can someone help me? please private void initConfig() { /* TO DO: initialize the following variables with information read from the config file * - MAXGAME * - logoIcon * - iconFile */ String snum; int MAXGAME; String [] iconFile=new String[NUMPLAYER]; String CONFIGFILE =("config.txt"); try { BufferedReader in = new BufferedReader (new FileReader (CONFIGFILE)); snum= in.readLine(); while (snum != null){ MAXGAME = Integer.parseInt (snum); snum= in.readLine (); logoIcon=snum; for (int i = 0; i < NUMPLAYER; i++){ snum=in.readLine (); iconFile[i]=snum; } } in.close(); }catch (IOException iox){ System.out.print ("Incorrect datatype: "); } } // in config.txt file 3 logo.bmp spongebob.bmp patrick.bmp |
Author: | HellblazerX [ Sat Jan 05, 2008 7:03 pm ] |
Post subject: | RE:Java exception.. why? |
You need to insert "snum = in.readLine ();" after your for loop, because, your snum variable is not null, therefore you go through the loop again. |
Author: | ICS_hard [ Sat Jan 05, 2008 11:17 pm ] |
Post subject: | RE:Java exception.. why? |
Thank you very much for your help. =) |
Author: | ICS_hard [ Sun Jan 13, 2008 12:20 pm ] |
Post subject: | Re: Java exception.. why? |
Now i have another problem: I keep getting an error?? why?i am tryinng to check the column if it already has a chip on it public void play (int column) { row=ConnectFour.checkCol(row, column); gui.setPiece(row, column,curPlayer); } public int checkCol (int column, int NUMROW, int NUMPLAYER) { if ( grid[row][col]==0 || grid [row][col]==1){ row--; } return row; } ![]() |
Author: | OneOffDriveByPoster [ Sun Jan 13, 2008 12:28 pm ] |
Post subject: | Re: Java exception.. why? |
What error are you getting? Please use [syntax="java"] tags so people can read your code easier. |
Author: | HellblazerX [ Mon Jan 14, 2008 9:00 am ] |
Post subject: | RE:Java exception.. why? |
Yes, please state what exception you're getting. It makes it much easier to help you that way. One thing I should point out to you, though I'm not sure if it'll fix your problem, is that you use 0 and 1 to represent your players' pieces. I'm assuming for spaces without any pieces, the value is not initialized. However, for Java, if you try to access an int variable that hasn't been initialized, Java automatically assigns it a value of 0. |
Author: | wtd [ Mon Jan 14, 2008 10:13 am ] |
Post subject: | RE:Java exception.. why? |
Please don't encourage the use of magic numbers. |
Author: | HellblazerX [ Mon Jan 14, 2008 1:37 pm ] |
Post subject: | Re: RE:Java exception.. why? |
wtd @ Mon Jan 14, 2008 10:13 am wrote: Please don't encourage the use of magic numbers.
O no, sorry, I wasn't trying to do that. Also, I just realized that my post wasn't even complete. ICS_Hard, you should use 1 and 2 to represent your player pieces, and empty spaces should be represented by 0. And ya, don't use magic numbers, initialize all your values. |
Author: | OneOffDriveByPoster [ Mon Jan 14, 2008 6:59 pm ] |
Post subject: | Re: RE:Java exception.. why? |
HellblazerX @ Mon Jan 14, 2008 1:37 pm wrote: wtd @ Mon Jan 14, 2008 10:13 am wrote: Please don't encourage the use of magic numbers.
O no, sorry, I wasn't trying to do that. Also, I just realized that my post wasn't even complete. ICS_Hard, you should use 1 and 2 to represent your player pieces, and empty spaces should be represented by 0. And ya, don't use magic numbers, initialize all your values. |