除了5.0之外,我的应用程序在每个版本上运行良好。 在那个版本中,每个有一个捆绑传递它的活动会导致一些数据崩溃..
这是logcat:
05-09 01:37:43.733 6371-6371/com.pttest.com.pockettankstips E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.pttest.com.pockettankstips, PID: 6371
java.lang.VerifyError: Rejecting class com.pttest.com.pockettankstips.compare because it failed compile-time verification (declaration of 'com.pttest.com.pockettankstips.compare' appears in /data/data/com.pttest.com.pockettankstips/files/instant-run/dex/slice-slice_9-classes.dex)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.Class.newInstance(Class.java:1572)
at android.app.Instrumentation.newActivity(Instrumentation.java:1065)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2199)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
以下是我打开活动的代码:
Intent co = new Intent("com.pttest.com.pockettankstips.compare");
Bundle compare = new Bundle();
compare.putString("index", "3 Shot");
co.putExtras(compare);
startActivity(co);
Toast.makeText(getBaseContext(), "Select Second Weapon to Compare!", Toast.LENGTH_LONG).show();
break;
我将如何在我即将开启的活动中收到Bundle ..
c1 = (Spinner) findViewById(R.id.cspin1);
c2 = (Spinner) findViewById(R.id.cspin2);
c1.setAdapter(new MyAdapter(this, R.layout.spinada, weapon));
c2.setAdapter(new MyAdapter1(this, R.layout.spinada, weapon1));
c1.setOnItemSelectedListener(this);
c2.setOnItemSelectedListener(this);
Bundle compare = getIntent().getExtras();
String compone = compare.getString("index", "3 Shot");
String[] weaponone = getResources().getStringArray(R.array.weapalpha);
x = Arrays.asList(weaponone).indexOf(compone);
c1.setSelection(x);
在我尝试在Bundle中发送int
的活动中,它工作正常,但当我尝试发送String
时,它会崩溃..
答案 0 :(得分:1)
我的上一个项目有错误,如下所示,我解决了问题。
java.lang.VerifyError:拒绝类 com.harshad.syncV4.android.module.ModuleTest因为失败了 编译时验证(声明 'com.harshad.syncV4.android.module.ModuleTest'出现在 /data/app/com.harshad.syncV4.android-1/base.apk)
Android OS版本5.0.1中会出现此错误。
我在我的代码中这样做。
try {
synchronized (this) {
this.wait(100);
}
} catch (InterruptedException e) {
/* Exception message can be captured here */
}
try / catch块内的同步块
当我在synchronized块中设置try / catch时 - 应用程序开始像往常一样工作。顺便说一句,在Android OS 5.0.1之前,这种方法没有问题。我认为这是因为新的ART编译器。
synchronized (this) {
try {
this.wait(testActionItem.getDelay());
} catch (InterruptedException e) {
/* Exception message can be captured here */
}
}
答案 1 :(得分:1)
试试这个:
String compone = compare.getString("index");
而不是
String compone = compare.getString("index", "3 Shot");
在您想要打开的第二个活动中。
希望这会对你有所帮助。