Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NumberFormat exception for null

 
anvi kon
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a code like below



Can anyone help me in this case?

thanks
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In addition to what mohamed said, I think you mean to set an element of lstr to "AAA"...

...rather than lstr itself...

Yes...?
 
Henry Wong
author
Marshal
Pie
Posts: 21500
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
anvi kon
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post the entire stack trace.
 
henry xu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21500
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I recommend posting the correct code -- the one that caused the runtime error. The code posted so far, can't compile.

 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic