java.lang.NullPointerException by parsing a string into an int
Hi,
I am trying to call a method with the first argument as an int.
I have successfully tested to call it with normalint, it works.
The problem is that the int i need to send has first to be casted from a string ( a jtext field basically)
what i do is :
destAddrInt = (int)Integer.parseInt(destAddr.trim());
this.sendCommand(destAddrInt , cmdShortArray);
but what ever i try it will not work, i always get thejava.lang.NullPointerException.
i have even tried to copy the value into an int:
destAddrInt = (int)Integer.parseInt(destAddr.trim());
int dum;
dum = destAddrInt;
this.sendCommand(dum, cmdShortArray);
What can I do?
Thanks for your help!
[856 byte] By [
fl88uja] at [2007-11-27 10:50:19]

You need to figure out what is actually throwing the null pointer exception.
If I had to guess, I'd say it's in the call to the trim() method on destAddr. Are you sure destAddr is a valid reference to a string object prior to calling the trim() method on it?
b.
>Why do you need to typecast the int again into an integer after you have parsed it?
This was actually my last try (I did several tries to find a solution)!
Ok, know I did follow the stack trace with ex.printStackTrace(); and found that the exception was afterward (some uninitialized Set).
And now it work, and of course even with
Integer.parseInt(destAddr.trim())
>If I had to guess, I'd say it's in the call to the trim() method on destAddr.
Trim has not be a problem).
Thanks for your help!