aspose file tools*
The moose likes Beginning Java and the fly likes Keep getting this error and not sure why Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Keep getting this error and not sure why" Watch "Keep getting this error and not sure why" New topic
Author

Keep getting this error and not sure why

Chris Wells
Greenhorn

Joined: Apr 24, 2009
Posts: 5
If anyone can take a few minutes and help me, I would be unbelievably grateful. I have been staring at this program for hours now and the solution is probably pretty simple.

My program looks like it should work perfectly and it does not register any errors until I run it.
Then, when I run it, I get:

Exception in thread "main" java.lang.NumberFormatException: For input string: "Chris"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:447)
at java.lang.Integer.parseInt(Integer.java:497)
at grade_book_methods.load_array(grade_book_methods.java:32)
at grade_book_methods.main(grade_book_methods.java:10)

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18120
    
  39

Exception in thread "main" java.lang.NumberFormatException: For input string: "Chris"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:447)
at java.lang.Integer.parseInt(Integer.java:497)
at grade_book_methods.load_array(grade_book_methods.java:32)
at grade_book_methods.main(grade_book_methods.java:10)


The stacktrace pretty much tells you everything... In your code, the grade_book_methods class, you have a method called load_array(). In line 32 of the java file, within that method, you call the parseInt() method, which is used to convert a string into an integer.

However, the string that you passed is "Chris", which is not a valid integer, and generated a NumberFormatException.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Chris Wells
Greenhorn

Joined: Apr 24, 2009
Posts: 5
Thank you so much for responding Henry.

After I figure out how to correct that error, is that the only one I am going to have to worry about?

What about the other four lines in the error message?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18120
    
  39

After I figure out how to correct that error, is that the only one I am going to have to worry about?

What about the other four lines in the error message?


It's a stack trace, the whole error message is one error. Once you get comfortable with reading it, you'll learn to ignore what is not relevant.

But if you want to know what it is saying...

-- The load_array() method was called from the main() method, at line 10.
-- Within the parseInt() method that you called, it called an overloaded parseInt() method.

Generally, what is important is where your code left off, and where the APIs start. It is not that important to look at the chain of methods within the API. And how you got to the load_array() method is only important, if you didn't expect it to be called that way.

Henry
Chris Wells
Greenhorn

Joined: Apr 24, 2009
Posts: 5
Henry, thank you for being so helpful tonight. I really appreciate your time.

I am playing around with my program, now that I know what the error means, and it seems that whatever I do, the error is still popping up, in different ways. Surely, there has to be some way to read in names and numbers.

I cannot get rid of the parseInt because the variable is an int and it will give me an error of having to convert an int to a String.

I am reading the data in from grades_in.txt which looks like:

Chris
84
90
Laura
95
100
Veronica
72
85
Mike
55
78
Bert
76
79
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18120
    
  39

It looks like your code reads the two grades first, then reads the name -- while the text file has the name first, then the two grades.

Henry
Chris Wells
Greenhorn

Joined: Apr 24, 2009
Posts: 5
It does not seem that way. It runs the column in the loop first (which is definied as [5], and then the row, and the row is defined as [2].

You seem like an experienced programmer. Can you point me in the right direction? I feel like I have been looking at this so long I am not looking at it right.
Chris Wells
Greenhorn

Joined: Apr 24, 2009
Posts: 5
Henry, I got it to work!!! Thank you so much!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Keep getting this error and not sure why
 
Similar Threads
do {} while statement illegal start of type
How can I add error handling facilities to this code?
Write a method that can be called, that will initialize the seating plan.
print invalid selction not working
Logic problem or invoke method problem