Jakibah Jakibah - 1 year ago 50
Java Question

Why does this conversion give an error?

I have this code in eclipse:

String A = String.valueOf(a);
String B = String.valueOf(b);
String C = String.valueOf(c);
String D = String.valueOf(d);
String E = String.valueOf(e);
String F = String.valueOf(f);
String G = String.valueOf(g);
String H = String.valueOf(h);
String I = String.valueOf(i);
String J = String.valueOf(j);
String K = String.valueOf(k);

String rawpassword = A+B+C+D+E+F+G+H+I+J+K;
int password = Integer.parseInt(rawpassword);

And it gives me this error

at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:495)
at java.lang.Integer.parseInt(Integer.java:527)
at com.jakibah.codegenerator.Main.Generate(Main.java:65)
at com.jakibah.codegenerator.Main.run(Main.java:24)
at java.lang.Thread.run(Thread.java:745)

But I do not understand why.
can someone help me?

Answer Source

The parseInt(String s) method throws a NumberFormatException if the argument is not a parseable Integer.

Make sure the String you pass to the method is a Number and is between -2^31 and 2^31 - 1

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download