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]
# 1

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.

bryanoa at 2007-7-29 11:24:34 > top of Java-index,Java Essentials,Java Programming...
# 2

> What can I do?

Look at the stack trace to find the line that causes the problem...

Then use a debugger or a system.out.println() to see whether the variables actually have the values you expect them to have.

CeciNEstPasUnProgrammeura at 2007-7-29 11:24:34 > top of Java-index,Java Essentials,Java Programming...
# 3

Why do you need to typecast the int again into an integer after you have parsed it?

Message was edited by:

Hanz_05

Hanz_05a at 2007-7-29 11:24:34 > top of Java-index,Java Essentials,Java Programming...
# 4

>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!

fl88uja at 2007-7-29 11:24:34 > top of Java-index,Java Essentials,Java Programming...