Reputation: 109
My app runs fine on every version except on 5.0. On that version every activity which has a bundle passing it some data crashes..
Here is the 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)
Here is my code to open the Activity:
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;
And how I receive the Bundle in the Activity I am about to open..
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);
In the Activities where I try to send an int
in the Bundle it works fine, but when I try to send a String
it crashes..
Upvotes: 4
Views: 575
Reputation: 803
try this:
String compone = compare.getString("index");
instead
String compone = compare.getString("index", "3 Shot");
in your second Activity which you want to open.
Hope this will help you.
Upvotes: 1
Reputation:
I have an error to my previous project like below and I Solve see the answer.
java.lang.VerifyError: Rejecting class com.harshad.syncV4.android.module.ModuleTest because it failed compile-time verification (declaration of 'com.harshad.syncV4.android.module.ModuleTest' appears in /data/app/com.harshad.syncV4.android-1/base.apk)
this error occur in Android OS version 5.0.1.
I am doing this in my code.
try {
synchronized (this) {
this.wait(100);
}
} catch (InterruptedException e) {
/* Exception message can be captured here */
}
Synchronized block inside try / catch block
When I set try / catch inside synchronized block - application start working as usual. By the way, prior to Android OS 5.0.1 there were no problem with such approach. I assume that this is because of the new ART compiler.
synchronized (this) {
try {
this.wait(testActionItem.getDelay());
} catch (InterruptedException e) {
/* Exception message can be captured here */
}
}
Upvotes: 2