我有一个非常简单的项目可以编译,但无法在模拟器上启动。问题在于这种方法:
private void bar(@Some String a) {} // java.lang.VerifyError
如果删除注释,则可以避免该问题
private void bar(String a) {} // OK
或方法可见性改变:
void bar(@Some String a) {} // OK
public void bar(@Some String a) {} // OK
protected void bar(@Some String a) {} // OK
知道原始方法有什么问题吗?这是一个dalvik错误,还是?
如果有人想尝试代码,这里是:
测试.java:
public class Test {
private void bar(@Some String a) {}
public void foo() {
bar(null);
}
}
一些.java:
public @interface Some {}
MainActivity.java:
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
new Test().foo();
}
}
堆栈跟踪:
ERROR/dalvikvm(1358): Could not find method com.my.Test.bar, referenced from method com.my.Test.foo
WARN/dalvikvm(1358): VFY: unable to resolve direct method 11: Lcom/my/Test;.bar (Ljava/lang/String;)V
WARN/dalvikvm(1358): VFY: rejecting opcode 0x70 at 0x0001
WARN/dalvikvm(1358): VFY: rejected Lcom/my/Test;.foo ()V
WARN/dalvikvm(1358): Verifier rejected class Lcom/my/Test;
DEBUG/AndroidRuntime(1358): Shutting down VM
WARN/dalvikvm(1358): threadid=3: thread exiting with uncaught exception (group=0x4000fe70)
ERROR/AndroidRuntime(1358): Uncaught handler: thread main exiting due to uncaught exception
ERROR/AndroidRuntime(1358): java.lang.VerifyError: com.my.Test
ERROR/AndroidRuntime(1358): at com.my.MainActivity.onCreate(MainActivity.java:13)
ERROR/AndroidRuntime(1358): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
ERROR/AndroidRuntime(1358): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
ERROR/AndroidRuntime(1358): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
ERROR/AndroidRuntime(1358): at android.app.ActivityThread.access$1800(ActivityThread.java:112)
ERROR/AndroidRuntime(1358): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
ERROR/AndroidRuntime(1358): at android.os.Handler.dispatchMessage(Handler.java:99)
ERROR/AndroidRuntime(1358): at android.os.Looper.loop(Looper.java:123)
ERROR/AndroidRuntime(1358): at android.app.ActivityThread.main(ActivityThread.java:3948)
ERROR/AndroidRuntime(1358): at java.lang.reflect.Method.invokeNative(Native Method)
ERROR/AndroidRuntime(1358): at java.lang.reflect.Method.invoke(Method.java:521)
ERROR/AndroidRuntime(1358): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
ERROR/AndroidRuntime(1358): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
ERROR/AndroidRuntime(1358): at dalvik.system.NativeStart.main(Native Method)