System.out.println("Your Received message is as following:");
while((recv_Message=buff2.readLine() )!=null){
System.out.println(recv_Message);
}
four_characters=recv_Message.substring(recv_Message.length() - 4);
Four_characters_Integers = Integer.parseInt(four_characters);
i sure have try and catch and defined all varibles above
but the problem it gives me this message when i use this statement:
four_characters=recv_Message.substring(recv_Message.length() - 4);
the Exception is as following:
java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:373)
at java.lang.Integer.parseInt(Integer.java:454)
at final_append.CopyBytes.main(CopyBytes.java:101)
Exception in thread "main"
how can i solve this??plz any help in
System.out.println( "'" + four_characters + "'" );
// is the four_characters string correct ?
// remove blanks with four_characters.trim();
// remove leading zeros
// remove fractional digits an decimal point
> Four_characters_Integers = Integer.parseInt(four_characters);
> i sure have try and catch and defined all varibles above
> but the problem it gives me this message when i use this statement:
> four_characters=recv_Message.substring(recv_Message.length() - 4);
/**
* String in int umwandeln
*
* @param numStr String numerisch
* @return Zahl
*/
public static final int str2int(
/*final*/String numStr )
{
if (empty( numStr ))
{
return 0;
}
numStr = numStr.trim();
int retInt = 0;
try
{
retInt = ( new Integer( numStr ) ).intValue();
}
catch (Throwable e)
{
;
}
return retInt;
} // end method str2int
/**
* String in Integer-Object umwandeln
*
* @param numStr String numerisch
* @return Intger-Object
*/
public static final Integer str2Integer(
final String numStr )
{
Integer retInteger = null;
retInteger = new Integer( str2int( numStr ) );
return retInteger;
} // end method str2Integer
/**
* String in Integer-Object umwandeln mit Rückgabe null wen nicht lesbar
*
* @param numStr String numerisch
* @return Integer-Object
*/
public static final Integer str2IntegerStrict(
final String numStr )
{
Integer retInteger = null;
try
{
retInteger = new Integer( numStr );
}
catch (Throwable e)
{
;// nicht lesbar , return null
}
return retInteger;
} // end method str2IntegerStrict
/**
* Parsen eines Strings in ein Integer,
* unter Nachsicht auf führende Nullen
* und nachfolgende Buchstaben oder
* Sonderzeichen
*
* @author Heiner Kücker
*/
public static Integer str2IntegerLenient(
final String pStr )
{
if (pStr == null
|| pStr.length() == 0)
{
return null; // Garbage in, Garbage out
}
final String trimmedStr = pStr.trim();
StringBuffer tmpStrBuff = new StringBuffer();
int iPos = 0;
//laufen über führende Nullen
for (; iPos < trimmedStr.length() - 1
&& trimmedStr.charAt( iPos ) == '0'; iPos++ )
;
//sammeln aller Digits
for (; iPos < trimmedStr.length()
&& Character.isDigit( trimmedStr.charAt( iPos ) ); iPos++ )
{
tmpStrBuff.append( trimmedStr.charAt( iPos ) );
}
Integer retInteger = null;
try
{
retInteger = new Integer( tmpStrBuff.toString() );
}
catch (Throwable e)
{
;
}
return retInteger;
}
/**
* String in int umwandeln mit Tolerierung enthaltener nichtnumerischer
Zeichen . <br/>
* geparst wird bis zum Auftreten nichtnumerischer Zeichen.<br/>
* Entfernung führender Nullen läßt sich zuschalten
* (Parameter pRemoveLeadingZeros).<br/>
*
* @param numStr String numerisch
* @return int Zahl
*/
public static final int str2intTolerant(
/*final*/String numStr , //--
final boolean pRemoveLeadingZeros )
{
if (empty( numStr ))
{
return 0;
}
numStr = numStr.trim();
if (pRemoveLeadingZeros)
{
//Entfernen führende Nullen
while (numStr.length() > 1
&& numStr.startsWith( "00" ))
{
numStr = numStr.substring( 1 );
}
}
// Entfernen evtl. nichtnumerische Zeichen am ende
for (int i = 0; i < numStr.length(); i++ )
{
if (numStr.charAt( i ) < '0'
|| numStr.charAt( i ) > '9')
{
// nicht numerisches Zeichen
numStr = numStr.substring( 0 , i );
break;
}
}
int retInt = 0;
try
{
retInt = ( new Integer( numStr ) ).intValue();
}
catch (Throwable e)
{
;
}
return retInt;
} // end method str2intTolerant
--
Heiner Kücker
www.heinerkuecker.de
www.control-and-command.de
/**
* String auf null, Länge 0 oder nur
* white spaces prüfen
*
* @param pStr zu prüfender String
* @return ob String empty (ja/nein)
*/
public static final boolean empty(
final String pStr )
{
return ( pStr == null //--
|| pStr.trim().length() < 1 );
} // end method empty
> iam sorry i cant read your language u seem f German can u reply in
> english???
Maybe you should use an english language newsgroup,
like comp.lang.java.*.
The "de" in "de.comp.lang.java" stands für "german".
Paul
--
Ich beantworte Java-Fragen per E-Mail nur gegen Bezahlung. Kostenpunkt
100 Euro pro angefangene Stunde. Bitte erwähne in der Anfrage, dass du
das akzeptierst, da ich sonst die E-Mail einfach ignoriere.
(In der Newsgroup fragen ist billiger und oft auch schneller.)