Question

The following code won't run and keeps throwing a Number Format Exception on the line the error is "Exception in thread "main" java.lang.NumberFormatException: For input string: "SAN 1905 1808+24 1512+17 1209+10 1708-06 2016-16 211831 211941 192652" ""

intAlt = Integer.parseInt(strAlt);

I'm not sure why this is happening and would appreciate any advice on the matter

private int getPos(String strAlt)
{
 int intAlt;
 int intPos =0;
 intAlt = Integer.parseInt(strAlt);
 switch (intAlt)
 {
  case 3:
   intPos = 4;
   break;
  case 6:
   intPos = 9;
   break;
  case 9:
   intPos = 17;
   break;   
  case 12:
   intPos = 25;
   break;
  case 18:
   intPos = 33;
   break;   
  case 24:
   intPos = 41;
   break; 
  case 30:
   intPos = 49;
   break;   
  case 34:
   intPos = 56;
   break;   
  case 39:
   intPos = 63;
   break;  
 }
 return intPos;
}
Was it helpful?

Solution

If you pass "SAN 1905 1808+24 1512+17 1209+10 1708-06 2016-16 211831 211941 192652" into getPos(String strAlt), it will execute:

intAlt = Integer.parseInt(strAlt);

Of course it will throw exception. See this doc

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top