1
votes

In my android project, I had originally targeted Android 6 and it all ran OK.

Now I'm running it on a Android 4.4 device (both a real device and an AVD) it crashes with an IllegalAccessException.

This is where it's crashing

    this.PractitionerList.add(new
            PractitionerItem(1, "01A1234E", "Mary", "1st", "London", "Y")

    );

PractitionerItem is a public class and PractitionerList is an arraylist declared like this

this.PractitionerList = new ArrayList();

This is the logcat....


08-08 02:47:05.491 2637-2637/org.nmc_uk.www.thenmc I/FirebaseInitProvider: FirebaseApp initialization unsuccessful 08-08 02:47:05.561 2637-2637/org.nmc_uk.www.thenmc W/dalvikvm: VFY: unable > to find class referenced in signature (Landroid/view/SearchEvent;) 08-08 02:47:05.561 2637-2637/org.nmc_uk.www.thenmc I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested 08-08 02:47:05.561 2637-2637/org.nmc_uk.www.thenmc W/dalvikvm: VFY: unable to resolve interface method 19611: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z 08-08 02:47:05.561 2637-2637/org.nmc_uk.www.thenmc D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002 08-08 02:47:05.571 2637-2637/org.nmc_uk.www.thenmc I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode 08-08 02:47:05.571 2637-2637/org.nmc_uk.www.thenmc W/dalvikvm: VFY: unable to resolve interface method 19615: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode; 08-08 02:47:05.571 2637-2637/org.nmc_uk.www.thenmc D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002 08-08 02:47:05.891 2637-2637/org.nmc_uk.www.thenmc I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.widget.TintTypedArray.getChangingConfigurations 08-08 02:47:05.891 2637-2637/org.nmc_uk.www.thenmc W/dalvikvm: VFY: unable to resolve virtual method 649: Landroid/content/res/TypedArray;.getChangingConfigurations ()I 08-08 02:47:05.891 2637-2637/org.nmc_uk.www.thenmc D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002 08-08 02:47:05.891 2637-2637/org.nmc_uk.www.thenmc I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.widget.TintTypedArray.getType 08-08 02:47:05.891 2637-2637/org.nmc_uk.www.thenmc W/dalvikvm: VFY: unable to resolve virtual method 671: Landroid/content/res/TypedArray;.getType (I)I 08-08 02:47:05.911 2637-2637/org.nmc_uk.www.thenmc D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002 08-08 02:47:06.071 2637-2637/org.nmc_uk.www.thenmc D/dalvikvm: GC_FOR_ALLOC freed 141K, 7% free 2923K/3112K, paused 51ms, total 51ms 08-08 02:47:06.071 2637-2637/org.nmc_uk.www.thenmc I/dalvikvm-heap: Grow heap (frag case) to 3.502MB for 635808-byte allocation 08-08 02:47:06.091 2637-2646/org.nmc_uk.www.thenmc D/dalvikvm: GC_FOR_ALLOC freed 1K, 6% free 3542K/3736K, paused 16ms, total 16ms[ 08-08 02:47:06.301 2637: 2637 D/ ]HostConnection::get() New Host Connection established 0xb903efa0, tid 2637 08-08 02:47:06.421 2637-2637/org.nmc_uk.www.thenmc D/OpenGLRenderer: Enabling debug mode 0 08-08 02:47:13.121 2637-2637/org.nmc_uk.www.thenmc I/dalvikvm: Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawable 08-08 02:47:13.121 2637-2637/org.nmc_uk.www.thenmc W/dalvikvm: VFY: unable to resolve virtual method 612: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable; 08-08 02:47:13.121 2637-2637/org.nmc_uk.www.thenmc D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002 08-08 02:47:13.121 2637-2637/org.nmc_uk.www.thenmc I/dalvikvm: Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawableForDensity 08-08 02:47:13.121 2637-2637/org.nmc_uk.www.thenmc W/dalvikvm: VFY: unable to resolve virtual method 614: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable; 08-08 02:47:13.121 2637-2637/org.nmc_uk.www.thenmc D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002 08-08 02:47:13.161 2637-2637/org.nmc_uk.www.thenmc D/---:: listView.setOnItemClickListener 08-08 02:47:15.021 2637-2637/org.nmc_uk.www.thenmc I/Choreographer: Skipped 110 frames! The application may be doing too much work on its main thread. 08-08 02:47:16.841 2637-2637/org.nmc_uk.www.thenmc D/---:: Inserting .. 08-08 02:47:16.841 2637-2637/org.nmc_uk.www.thenmc E/dalvikvm: Could not find class 'org.nmc_uk.www.thenmc.PractitionerItem$1', referenced from method org.nmc_uk.www.thenmc.PractitionerItem. 08-08 02:47:16.841 2637-2637/org.nmc_uk.www.thenmc W/dalvikvm: VFY: unable to resolve new-instance 9673 (Lorg/nmc_uk/www/thenmc/PractitionerItem$1;) in Lorg/nmc_uk/www/thenmc/PractitionerItem; 08-08 02:47:16.841 2637-2637/org.nmc_uk.www.thenmc D/dalvikvm: VFY: replacing opcode 0x22 at 0x0000 08-08 02:47:16.841 2637-2637/org.nmc_uk.www.thenmc D/dalvikvm: DexOpt: unable to opt direct call 0xfe57 at 0x02 in Lorg/nmc_uk/www/thenmc/PractitionerItem;. 08-08 02:47:16.901 2637-2637/org.nmc_uk.www.thenmc W/dalvikvm: Exception Ljava/lang/NoClassDefFoundError; thrown while initializing Lorg/nmc_uk/www/thenmc/PractitionerItem; 08-08 02:47:16.901 2637-2637/org.nmc_uk.www.thenmc D/AndroidRuntime: Shutting down VM 08-08 02:47:16.901 2637-2637/org.nmc_uk.www.thenmc W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xb2d53b20) 08-08 02:47:18.551 2637-2637/org.nmc_uk.www.thenmc E/AndroidRuntime: FATAL EXCEPTION: main Process: org.nmc_uk.www.thenmc, PID: 2637 java.lang.IllegalStateException: Could not execute method for android:onClick

at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:275) at android.view.View.performClick(View.java:4438)

This is the class....

package org.nmc_uk.www.xxxxx;

import android.os.Parcel;
import android.os.Parcelable;

public class PractitionerItem implements Parcelable {
Integer PRN;
String PIN;
String Fname;
String Lname;
String Town;
String YesNo;



@Override
public int describeContents() {
    // TODO Auto-generated method stub
    return 0;
}

@Override
public void writeToParcel (Parcel dest, int flags) {
    dest.writeInt(PRN);
    dest.writeString(PIN);
    dest.writeString(Fname);
    dest.writeString(Lname);
    dest.writeString(Town);
    dest.writeString(YesNo);
}

private PractitionerItem(Parcel in){
    this.PRN = in.readInt();
    this.PIN = in.readString();
    this.Fname = in.readString();
    this.Lname = in.readString();
    this.Town = in.readString();
    this.YesNo = in.readString();
}

public static final Creator<PractitionerItem> CREATOR = new Creator<PractitionerItem>() {

    @Override
    public PractitionerItem createFromParcel(Parcel source) {
        return new PractitionerItem(source);
    }

    @Override
    public PractitionerItem[] newArray(int size) {
        return new PractitionerItem[size];
    }
};
public PractitionerItem(Integer PRN, String PIN, String Fname, String Lname, String Town, String YesNo){
    this.PRN = PRN;
    this.PIN = PIN;
    this.Fname = Fname;
    this.Lname = Lname;
    this.Town = Town;
    this.YesNo = YesNo;
}

}

..... and this (the main bits) from the class that calls it...


Public class SearchTheRegister extends AppCompatActivity {

private ArrayList<PractitionerItem> PractitionerList;

private CustomAdapter practitioner_adapter;
.
.
.

 //// THIS LINE IS WHERE IT FAILS /////////////// 
    this.PractitionerList.add(new
            PractitionerItem(1, "01A1234E", "Mary", "1st", "London", "Y")

    );

Any ideas?

Sam

2
Post the whole logcat of the crash.Vucko
full code + logcat will help others feel it easy to figure out what the problem isFxVt
do you init your list in your application? and when you run app it suddenly gets crash?savepopulation
Hi,To answer your 2nd question 1st, it only crashes at this line. everything else runs fine. I recoded the failing line like this PractitionerItem pract = new PractitionerItem(1, "01A1234E", "Mary", "1st", "London", "Y")Sam
Hi,To answer your 2nd question 1st, it only crashes at this line. everything else runs fine. I recoded the failing line like this . . PractitionerItem pract = new PractitionerItem(1, "01A1234E", "Mary", "1st", "London", "Y") . and it fails at tat line, so it's not related to the list not being initialised. . As I said it works fine when I target api version 23. It only fails when it targets api version 19. . So is there anything different about these two versions in the way you code parcelable classes?Sam

2 Answers

0
votes

I'm not sure if this'll fix your problem but i have similar issue and i realised my parcelable implementation is wrong. I re generated a parcelable implementation for you below:

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeValue(this.PRN);
        dest.writeString(this.PIN);
        dest.writeString(this.Fname);
        dest.writeString(this.Lname);
        dest.writeString(this.Town);
        dest.writeString(this.YesNo);
    }

    public PractitionerItem() {
    }

    protected PractitionerItem(Parcel in) {
        this.PRN = (Integer) in.readValue(Integer.class.getClassLoader());
        this.PIN = in.readString();
        this.Fname = in.readString();
        this.Lname = in.readString();
        this.Town = in.readString();
        this.YesNo = in.readString();
    }

    public static final Creator<PractitionerItem> CREATOR = new Creator<PractitionerItem>() {
        @Override
        public PractitionerItem createFromParcel(Parcel source) {
            return new PractitionerItem(source);
        }

        @Override
        public PractitionerItem[] newArray(int size) {
            return new PractitionerItem[size];
        }
    };

If this won't work you can try to add MultiDex support to your app. There is a strange issue about Kitkat, ArrayList and Parcelable.

To add multidex support:

First change your gradle like below:

android {
    defaultConfig {
        ...
        multiDexEnabled true
        ...
    }
}

dependencies {
  ...
  compile 'com.android.support:multidex:1.0.0'
  ...

}

Second extend your Application from Multidex Application or call Multidex.init in OnCreate:

public class YourApplication extends MultiDexApplication
{
    ...
}

or

public class YourApplication extends Application
{
    protected void attachBaseContext(Context base)
    {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
}

If these solutions don't work please let me know and let us try to figure out a new fix.

Good luck.

0
votes

You can try making Integer primitive.