I had recently released an Android game in google play and I received a crash report of this NumberFormatException
I even pin pointed the code from which it is coming from.. But the thing which concerns me the most is the exception is not being thrown in any of the devices i have tested (and i have tested it in many devices)..
I have a string file arranged like this…
“10.48,1.6,90.0,1.155,1.73” where each float is separated by a comma… I don’t know why this weird exception has occurred for the user of my app 🙁
Here is the code which i am using to parse from the file
while(j<line.length())
{
if(line.charAt(j) == ',')
{
endingPoint = j;
planetList[i].add(Float.valueOf(line.substring(startingPoint, endingPoint)));
startingPoint = j+1;
}
else if(line.charAt(j) == 's')
{
i++;
startingPoint = j+1;
}
j++;
}
and here is the line which is throwing the exception…
cam = new Camera(Float.valueOf(df.format(worldWidth)),fourPointEightFixer);
HERE IS THE STACK TRACE THE KIND USER OF MY APP SENT:
java.lang.NumberFormatException
at org.apache.harmony.luni.util.FloatingPointParser.parseFltImpl(Native Method)
at org.apache.harmony.luni.util.FloatingPointParser.parseFloat(FloatingPointParser.java:321)
at java.lang.Float.parseFloat(Float.java:323)
at java.lang.Float.valueOf(Float.java:362)
at com.OnMyOwn.Game.WackyGravity.<init>(WackyGravity.java:97)
at com.OnMyOwn.Game.LevelChooserMod.initiateGame(LevelChooserMod.java:550)
at com.OnMyOwn.Game.LevelChooserMod.onButtonTouchUp(LevelChooserMod.java:576)
at com.OnMyOwn.Game.LevelChooserMod.update(LevelChooserMod.java:384)
at com.OnMyOwn.framework.impl.GLGame.onDrawFrame(GLGame.java:165)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1363)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)
This issue is caused by language so catch this exception in case of “.” and replace this with comma “,” if you are using pattern like this “##.###”