在我的android项目中,我本来以Android 6为目标,但一切正常。

现在,我在Android 4.4设备(真实设备和AVD)上运行它,并因IllegalAccessException崩溃。

这是崩溃的地方

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

    );


PractitionerItem是一个公共类,而PractitionerList是一个这样声明的数组列表

this.PractitionerList = new ArrayList();

这是logcat。




  08-08 02:47:05.491 2637-2637 / org.nmc_uk.www.thenmc I / FirebaseInitProvider:FirebaseApp初始化失败
  08-08 02:47:05.561 2637-2637 / org.nmc_uk.www.thenmc W ​​/ dalvikvm:VFY:无法>查找签名中引用的类(Landroid / view / SearchEvent;)
  08-08 02:47:05.561 2637-2637 / org.nmc_uk.www.thenmc I / dalvikvm:找不到方法android.view.Window $ Callback.onSearchRequested,从方法android.support.v7.view.WindowCallbackWrapper引用。 onSearchRequested
  08-08 02:47:05.561 2637-2637 / org.nmc_uk.www.thenmc W ​​/ dalvikvm:VFY:无法解析接口方法19611:Landroid / view / Window $ Callback; .onSearchRequested(Landroid / view / SearchEvent;) ž
  08-08 02:47:05.561 2637-2637 / org.nmc_uk.www.thenmc D / dalvikvm:VFY:在0x0002处替换操作码0x72
  08-08 02:47:05.571 2637-2637 / org.nmc_uk.www.thenmc I / dalvikvm:找不到方法android.view.Window $ Callback.onWindowStartingActionMode,该方法是从方法android.support.v7.view.WindowCallbackWrapper引用的。 onWindowStartingActionMode
  08-08 02:47:05.571 2637-2637 / org.nmc_uk.www.thenmc W ​​/ dalvikvm:VFY:无法解析接口方法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:在0x0002处替换操作码0x72
  08-08 02:47:05.891 2637-2637 / org.nmc_uk.www.thenmc I / dalvikvm:找不到方法android.content.res.TypedArray.getChangingConfigurations,该引用是从方法android.support.v7.widget.TintTypedArray引用的。 getChangingConfigurations
  08-08 02:47:05.891 2637-2637 / org.nmc_uk.www.thenmc W ​​/ dalvikvm:VFY:无法解析虚拟方法649:Landroid / content / res / TypedArray; .getChangingConfigurations()I
  08-08 02:47:05.891 2637-2637 / org.nmc_uk.www.thenmc D / dalvikvm:VFY:在0x0002处替换操作码0x6e
  08-08 02:47:05.891 2637-2637 / org.nmc_uk.www.thenmc I / dalvikvm:找不到方法android.content.res.TypedArray.getType,该方法是从方法android.support.v7.widget.TintTypedArray引用的。 getType
  08-08 02:47:05.891 2637-2637 / org.nmc_uk.www.thenmc W ​​/ dalvikvm:VFY:无法解析虚拟方法671:Landroid / content / res / TypedArray; .getType(I)I
  08-08 02:47:05.911 2637-2637 / org.nmc_uk.www.thenmc D / dalvikvm:VFY:在0x0002处替换操作码0x6e
  08-08 02:47:06.071 2637-2637 / org.nmc_uk.www.thenmc D / dalvikvm:GC_FOR_ALLOC释放了141K,7%释放了2923K / 3112K,暂停了51ms,总计51ms
  08-08 02:47:06.071 2637-2637 / org.nmc_uk.www.thenmc I / dalvikvm-heap:将堆(frag情况)增加到3.502MB以分配635808字节
  08-08 02:47:06.091 2637-2646 / org.nmc_uk.www.thenmc D / dalvikvm:GC_FOR_ALLOC释放了1K,6%释放了3542K / 3736K,暂停了16ms,总计16ms [08-08 02:47:06.301 2637: 2637 D /] HostConnection :: get()建立新的主机连接0xb903efa0,tid 2637
  08-08 02:47:06.421 2637-2637 / org.nmc_uk.www.thenmc D / OpenGLRenderer:启用调试模式0
  08-08 02:47:13.121 2637-2637 / org.nmc_uk.www.thenmc I / dalvikvm:找不到方法android.content.res.Resources.getDrawable,该方法是从方法android.support.v7.widget.ResourcesWrapper引用的。 getDrawable
  08-08 02:47:13.121 2637-2637 / org.nmc_uk.www.thenmc W ​​/ dalvikvm:VFY:无法解析虚拟方法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:在0x0002处替换操作码0x6e
  08-08 02:47:13.121 2637-2637 / org.nmc_uk.www.thenmc I / dalvikvm:找不到方法android.content.res.Resources.getDrawableForDensity,该方法是从方法android.support.v7.widget.ResourcesWrapper引用的。 getDrawableForDensity
  08-08 02:47:13.121 2637-2637 / org.nmc_uk.www.thenmc W ​​/ dalvikvm:VFY:无法解析虚拟方法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:在0x0002处替换操作码0x6e
  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:跳过了110帧!该应用程序可能在其主线程上做过多的工作。
  08-08 02:47:16.841 2637-2637 / org.nmc_uk.www.thenmc D / --- ::插入..
  08-08 02:47:16.841 2637-2637 / org.nmc_uk.www.thenmc E / dalvikvm:找不到方法org.nmc_uk.www.thenmc引用的类'org.nmc_uk.www.thenmc.PractitionerItem $ 1' .PractitionerItem。
  08-08 02:47:16.841 2637-2637 / org.nmc_uk.www.thenmc W ​​/ dalvikvm:VFY:无法解析Lorg / nmc_uk /中的新实例9673(Lorg / nmc_uk / www / thenmc / PractitionerItem $ 1;) www / thenmc / PractitionerItem;
  08-08 02:47:16.841 2637-2637 / org.nmc_uk.www.thenmc D / dalvikvm:VFY:在0x0000处替换操作码0x22
  08-08 02:47:16.841 2637-2637 / org.nmc_uk.www.thenmc D / dalvikvm:DexOpt:无法选择在Lorg / nmc_uk / www / thenmc / PractitionerItem;中的0x02处直接调用0xfe57。
  08-08 02:47:16.901 2637-2637 / org.nmc_uk.www.thenmc W ​​/ dalvikvm:异常Ljava / lang / NoClassDefFoundError;初始化Lorg / nmc_uk / www / thenmc / PractitionerItem时抛出;
  08-08 02:47:16.901 2637-2637 / org.nmc_uk.www.thenmc D / AndroidRuntime:关闭VM
  08-08 02:47:16.901 2637-2637 / org.nmc_uk.www.thenmc W ​​/ dalvikvm:threadid = 1:线程以未捕获的异常退出(group = 0xb2d53b20)
  08-08 02:47:18.551 2637-2637 / org.nmc_uk.www.thenmc E / AndroidRuntime:FATAL EXCEPTION:main
  流程:org.nmc_uk.www.thenmc,PID:2637
  java.lang.IllegalStateException:无法执行android:onClick的方法
  
                                                                           在android.support.v7.app.AppCompatViewInflater $ DeclaredOnClickListener.onClick(AppCompatViewInflater.java:275)在android.view.View.performClick(View.java:4438)


这是课程。

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;
}


}

.....和调用它的类中的(主要位)...



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")

    );


有任何想法吗?

山姆

最佳答案

我不确定这是否可以解决您的问题,但是我也遇到类似的问题,并且我意识到我的包裹实施方式是错误的。我在下面为您重新生成了可打包的实现:

    @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];
        }
    };


如果这不起作用,您可以尝试为您的应用添加MultiDex支持。关于KitkatArrayList和Parcelable,存在一个奇怪的问题。

要添加multidex支持:

首先像下面这样改变gradle:

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

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


}

其次,从Multidex Application扩展您的Application或在Multidex.init中调用OnCreate

public class YourApplication extends MultiDexApplication
{
    ...
}


要么

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


如果这些解决方案不起作用,请告诉我,让我们尝试找出新的解决方案。

祝好运。

09-05 12:26