This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes NumberFormat exception for null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "NumberFormat exception for null" Watch "NumberFormat exception for null" New topic
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
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3054
    
  33

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: 18101
    
  39

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: 18101
    
  39


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

Joined: Sep 08, 2007
Posts: 3054
    
  33

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.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NumberFormat exception for null
 
Similar Threads
Strings
Strings
number formatting????
formatting amount
Leading zeros