convert between integer and string

The problem is like this:

Data transfer via socket. The sending side convert integer into string and the receiving side convert string back to integer. An exception appears when the receiving side wants to convert a text content into an integer. The exception is:

java.lang.NumberFormatException: null

at java.lang.Integer.parseInt(Integer.java:382)

at java.lang.Integer.parseInt(Integer.java:463)

The way I convert the integer into String (in an xml element creation method) is:

type.appendChild( document.createTextNode(new Integer(msg.type).toString()));

The way I convert the xml element String value back to integer is:

msgObj.type = Integer.parseInt(data.item(0).getNodeValue());//data.item(0).getNodeValue() returns a String value.

The run time exception occurs when doing the converting back to the integer. What could it be wrong?

Thanks.

[917 byte] By [ilikeit888] at [2007-9-27 18:58:22]
# 1
If on either the new Integer(String) or the Integer.parseInt(String) methods the String object you pass it is null or is not formatted as an Integer, then you will get the NumberFormatException. Since it is saying NumberFormatException : null, then you must be passing it a null value.
yoda23 at 2007-7-6 20:59:14 > top of Java-index,Archived Forums,Java Programming...
# 2
Your basic method for converting is fine, but apparently "data.item(0).getNodeValue()" returns null in this case. Can't say why without seeing more code, though.
hhor at 2007-7-6 20:59:14 > top of Java-index,Archived Forums,Java Programming...
# 3
My checking shows that there is something wrong when I convert int to string first. Can you see what is wrong?
ilikeit888 at 2007-7-6 20:59:14 > top of Java-index,Archived Forums,Java Programming...