Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Java exception.. why?
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
ICS_hard




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
HellblazerX




PostPosted: 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.
ICS_hard




PostPosted: Sat Jan 05, 2008 11:17 pm   Post subject: RE:Java exception.. why?

Thank you very much for your help. =)
ICS_hard




PostPosted: 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;
}

Neutral AHH
OneOffDriveByPoster




PostPosted: 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.
HellblazerX




PostPosted: 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.
wtd




PostPosted: Mon Jan 14, 2008 10:13 am   Post subject: RE:Java exception.. why?

Please don't encourage the use of magic numbers.
HellblazerX




PostPosted: 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.
Sponsor
Sponsor
Sponsor
sponsor
OneOffDriveByPoster




PostPosted: 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.
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.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: