I got a very strange error on my android apk that only appears if I run it on galaxy 3 froyo device (runs fine on emulator and galaxy s2).
The error comes from the Ontouchevent class, and if I comment out some lines of the code, the error disappears. However those lines have nothing to do with this error (that part of the code has not even executed).
For example, if I add one line of
if(sound)try{SoundManager.playSound(1,1);}catch(Exception e){e.printStackTrace();}
to a switch case inside the ontouchevent keydown, it does not cause error, but if I add 6 of them (not at once), it crashes.
I cannot paste the whole source code because it’s long, but the error is the following:
02-25 19:11:59.893: WARN/dalvikvm(5754): VFY: invalid switch start: at 88, switch offset -32758, count 33104
02-25 19:11:59.928: WARN/dalvikvm(5754): VFY: rejected Lspaceshooter/apk/OpenGLRenderer;.onTouchEvent (Landroid/view/MotionEvent;)Z
02-25 19:11:59.928: WARN/dalvikvm(5754): Verifier rejected class Lspaceshooter/apk/OpenGLRenderer;
02-25 19:11:59.928: DEBUG/AndroidRuntime(5754): Shutting down VM
02-25 19:11:59.928: WARN/dalvikvm(5754): threadid=1: thread exiting with uncaught exception (group=0x4001d7d0)
02-25 19:11:59.943: ERROR/AndroidRuntime(5754): FATAL EXCEPTION: main
02-25 19:11:59.943: ERROR/AndroidRuntime(5754): java.lang.VerifyError: spaceshooter.apk.OpenGLRenderer
02-25 19:11:59.943: ERROR/AndroidRuntime(5754): at spaceshooter.apk.Main.onCreate(Main.java:84)
02-25 19:11:59.943: ERROR/AndroidRuntime(5754): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-25 19:11:59.943: ERROR/AndroidRuntime(5754): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
02-25 19:11:59.943: ERROR/AndroidRuntime(5754): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
02-25 19:11:59.943: ERROR/AndroidRuntime(5754): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
02-25 19:11:59.943: ERROR/AndroidRuntime(5754): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
02-25 19:11:59.943: ERROR/AndroidRuntime(5754): at android.os.Handler.dispatchMessage(Handler.java:99)
02-25 19:11:59.943: ERROR/AndroidRuntime(5754): at android.os.Looper.loop(Looper.java:123)
02-25 19:11:59.943: ERROR/AndroidRuntime(5754): at android.app.ActivityThread.main(ActivityThread.java:4627)
02-25 19:11:59.943: ERROR/AndroidRuntime(5754): at java.lang.reflect.Method.invokeNative(Native Method)
02-25 19:11:59.943: ERROR/AndroidRuntime(5754): at java.lang.reflect.Method.invoke(Method.java:521)
02-25 19:11:59.943: ERROR/AndroidRuntime(5754): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
02-25 19:11:59.943: ERROR/AndroidRuntime(5754): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
02-25 19:11:59.943: ERROR/AndroidRuntime(5754): at dalvik.system.NativeStart.main(Native Method)
Any idea ?
It seems some classes in the code simply contains too many lines for the verifier. The problem occurs only on android 2.2 system or below.
The solution seems to cut the class to smaller classes and calling them inside the original class. Seems bit stupid, but it works.