Number format problem

Hi

My code doesnt work.

And i hope you can tell me why.

This is a method in my acc class.

publicvoid setAccount(String name){

try

{

BufferedReader in =new BufferedReader(new FileReader(name));

for (int itr = 0; itr < maxlines; itr++){

if (itr == 0){

levelstring = in.readLine();

levelstring.trim();

}

elseif (itr == 1){

xpstring = in.readLine();

xpstring.trim();

}

elseif (itr == 2){

hairstylestring = in.readLine();

hairstylestring.trim();

}

elseif (itr == 3){

haircolorstring = in.readLine();

haircolorstring.trim();

}

elseif (itr == 4){

genderstring = in.readLine();

genderstring.trim();

}

elseif (itr == 5){

shirtstring = in.readLine();

shirtstring.trim();

}

elseif (itr == 6){

legsstring = in.readLine();

legsstring.trim();

}

elseif (itr == 7){

xstring = in.readLine();

xstring.trim();

}

elseif (itr == 8){

ystring = in.readLine();

ystring.trim();

}

}

in.close();

}

catch (Exception e)

{

System.out.println("Cannot find Account");

}

xp= Integer.parseInt(xpstring);

level= Integer.parseInt(levelstring);

hairstyle= Integer.parseInt(hairstylestring);

haircolor= Integer.parseInt(haircolorstring);

gender= Integer.parseInt(genderstring);

shirt= Integer.parseInt(shirtstring);

legs= Integer.parseInt(legsstring);

x= Integer.parseInt(xstring);

y= Integer.parseInt(ystring);

}

When i call this method the compiler says:

Exception in thread "main" java.lang.NumberFormatException: null

at java.lang.Integer.parseIny(Unknown Source)

at java.lang.Integer.parseIny(Unknown Source)

at acc.setAccount(acc.java:162)

at main.main(main.java:63)

The file that the program should read from looks like this

1

5431

4

2

1

5

1

53

24

Somebody plz help me

Message was edited by:

javaguy387

[3735 byte] By [javaguy387a] at [2007-11-27 11:32:59]
# 1

You're trying to parse a null reference to an int.

String s = "666";

System.out.println(Integer.parseInt(s));

s = null;

System.out.println(Integer.parseInt(s)); // <- no can do!

prometheuzza at 2007-7-29 16:48:43 > top of Java-index,Java Essentials,New To Java...
# 2

MOst probably your problem is due to the read line containing characters other than nos

Try sysout of each line that is read.. you should be able to find out where the error is

n also towards the end u got x,y - are you declaring it somewhere

New_Kida at 2007-7-29 16:48:43 > top of Java-index,Java Essentials,New To Java...
# 3

Yes but where is the null?

javaguy387a at 2007-7-29 16:48:43 > top of Java-index,Java Essentials,New To Java...
# 4

>n also towards the end u got x,y - are you declaring it somewhere

Yep

javaguy387a at 2007-7-29 16:48:43 > top of Java-index,Java Essentials,New To Java...
# 5

> Yes but where is the null?

Try printing your variables before parsing them to an int. That way you see which variable is (still) null. This is called debugging.

prometheuzza at 2007-7-29 16:48:43 > top of Java-index,Java Essentials,New To Java...
# 6

Exception in thread "main" java.lang.NumberFormatException: null

Try sysout at the start of the loop- you should be able to pin point the error yourself man

New_Kida at 2007-7-29 16:48:43 > top of Java-index,Java Essentials,New To Java...
# 7

It works now thanks

javaguy387a at 2007-7-29 16:48:43 > top of Java-index,Java Essentials,New To Java...
# 8

at java.lang.Integer.parseIny(Unknown Source)

at java.lang.Integer.parseIny(Unknown Source)

That's a very weird runtime you're using that it has that method...

jwentinga at 2007-7-29 16:48:43 > top of Java-index,Java Essentials,New To Java...