I'm making a program that imitates the tabulation method (Quine McCluskey) and I'm trying to convert the input in String format to Integer format and finally back to String (in Binary form) format.
I got this error:
Exception in thread "main" java.lang.NumberFormatException: For input string: "" at java.lang.NumberFormatException.forInputString(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at java.lang.Integer.parseInt(Unknown Source)
and here's the line with the error:
String a = toBinary(Integer.parseInt(a1));
any tips on how should I better approach this conversion? Assuming that the input is correct (only numbers are on the String).
EDIT: I forgot to include this method..
public String toBinary(Integer input) {
String binString = Integer.toBinaryString(input);
while(binString.length()<8) //for PADDING zeroes up front
binString = "0" + binString;
System.out.println("\nBinString: " + binString);
return binString;
}
java.lang.Integer.parseInt, thus the issue is not intoBinary, but rather witha1which contains an empty String. You need to find our why.java.lang.Integer.parseInt(..). You need to debug that, but Stackoverflow can't help you to debug your code.String a = toBinary(Integer.parseInt(a1));works, right?a1is the culprit, thus this line is generally fine, but during runtimea1contains something you or your program doesn't expect. When you usetoBinary(Integer.parseInt("1234"));instead, when everything would work without an exception. If it does, then you need to debug the source ofa1s value and why it assigns an empty String. Maybe that code itself receives a value it doesn't expect and the empty String is just the initial/fallback value?