• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NumberFormat exception for null

 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a code like below



Can anyone help me in this case?

thanks
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...?
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please post the entire stack trace.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
reply
    Bookmark Topic Watch Topic
  • New Topic