
-----------------------------------
ICS_hard
Sat Jan 05, 2008 6:55 pm

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

-----------------------------------
HellblazerX
Sat Jan 05, 2008 7:03 pm

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.

-----------------------------------
ICS_hard
Sat Jan 05, 2008 11:17 pm

RE:Java exception.. why?
-----------------------------------
Thank you very much for your help. =)

-----------------------------------
ICS_hard
Sun Jan 13, 2008 12:20 pm

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;
  }

 :|   AHH

-----------------------------------
OneOffDriveByPoster
Sun Jan 13, 2008 12:28 pm

Re: Java exception.. why?
-----------------------------------
What error are you getting?  Please use [syntax="java"] tags so people can read your code easier.

-----------------------------------
HellblazerX
Mon Jan 14, 2008 9:00 am

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.

-----------------------------------
wtd
Mon Jan 14, 2008 10:13 am

RE:Java exception.. why?
-----------------------------------
Please don't encourage the use of magic numbers.

-----------------------------------
HellblazerX
Mon Jan 14, 2008 1:37 pm

Re: RE:Java exception.. why?
-----------------------------------
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.

-----------------------------------
OneOffDriveByPoster
Mon Jan 14, 2008 6:59 pm

Re: RE:Java exception.. why?
-----------------------------------
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.Those numbers are just as magic.  You can use _static final int_s as a poor man's enum to save yourself some trouble.  Java enums are great sometimes, but it really can be convenient when you just have int constants.
