java.lang.NumberFormatException for String to Int Java -
i have been searching answer this, , haven't been able find has rectified quite yet. i'm trying populate array, check if gets larger value. however, when run this, exception in thread "main" java.lang.numberformatexception: input string: "" error. here code it:
public void setreaddata() throws nosuchelementexception { try { (int = 0; < getrows(); i++) { string numbers = p.nextline(); string[] inputs = numbers.split(" "); if (inputs.length > getcols()) { system.out.println("there more columns size specified!\n"); system.exit(1); } (int j = 0; j < getcols(); j++) { int data = integer.parseint(inputs[j]); this.setdata(i,j,data); } } and error code is:
exception in thread "main" java.lang.numberformatexception: input string: "" @ java.lang.numberformatexception.forinputstring(numberformatexception.java:65) @ java.lang.integer.parseint(integer.java:504) @ java.lang.integer.parseint(integer.java:527) @ foo.bar.setreaddata(matrix.java:49) @ foo.bar.main(matrix.java:226) any appreciated!
----edit----
to clarify, old code worked was:
for (int = 0; < getrows(); i++) { p.nextline(); (int j = 0; j < getcols(); j++) { this.setdata(i,j,p.nextint()); } } however, there no checking whole line has been checked.
try this:
for (int j = 0; j < getcols(); j++) { if(!inputs[j].equals("")){ int data = integer.parseint(inputs[j]); this.setdata(i,j,data); } }
Comments
Post a Comment