| Author |
NumberFormat exception for null
|
anvi kon
Ranch Hand
Joined: Jan 08, 2010
Posts: 133
|
|
Hi,
I have a code like below
Can anyone help me in this case?
thanks
|
 |
Mohamed Sanaulla
Bartender
Joined: Sep 08, 2007
Posts: 2946
|
|
lstr and lststr- Are they different? You seemed to have used them interchangeably.
Also please post the code where this is being used. I dont see why there's is an NumberFormatException being thrown. Also a stacktrace would be helpful.
Use defensive programming technique and avoid trying to parse the Null values.
Update: Moreover lststr doesn't have any elements in it? It has all null elements. Try to initialize the array with some elements.
|
Mohamed Sanaulla | My Blog
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
In addition to what mohamed said, I think you mean to set an element of lstr to "AAA"...
...rather than lstr itself...
Yes...?
|
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16809
|
|
As a side question, how this this code ever compile? As there is no way the compiler will allow any variable, regardless of the type, to be treated as both an array and a string.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
anvi kon
Ranch Hand
Joined: Jan 08, 2010
Posts: 133
|
|
Here is the error I'm getting java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:415)
at java.lang.Integer.parseInt(Integer.java:497)
how would I resove this?
thanks
|
 |
Tom Reilly
Rancher
Joined: Jun 01, 2010
Posts: 618
|
|
|
Please post the entire stack trace.
|
 |
henry xu
Greenhorn
Joined: Apr 14, 2010
Posts: 2
|
|
|
Hi,the datatype of num is int, while the datatype of lstr[i] is String, so they cannot compare? lstr is the array of string, so lstr[i] sounds like more sensible
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16809
|
|
I recommend posting the correct code -- the one that caused the runtime error. The code posted so far, can't compile.
|
 |
Mohamed Sanaulla
Bartender
Joined: Sep 08, 2007
Posts: 2946
|
|
anvi kon wrote:Here is the error I'm getting java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:415)
at java.lang.Integer.parseInt(Integer.java:497)
how would I resove this?
thanks
If you would have posted the StackTrace and the code in your first post- You would surely have got the reason for the exception- with so many people willing to help you. Its always good to post the working code( a small prototype where you can capture the problem). What happens is sometimes the exception name might make it to seem obivous but with out the stacktrace we cannot identify at which line its being thrown and with out the code we cannot tell you why that exception is being thrown at that line.
|
 |
 |
|
|
subject: NumberFormat exception for null
|
|
|