android - 找不到指向 Parcelable 的运行时错误 NoClassDefFoundError

标签 android projects-and-solutions

请帮我解决这个问题,我被困在这里,我的应用程序可以在更高版本的设备 MOGO G3 和 Moto XPlay 上运行,但是当我在具有较低版本 (16) 的设备上测试时,它给我错误,即 NoClassDefFoundError。

这是我的 sdk 配置:

minSdkVersion 16 targetSdkVersion 22

这是 android 在运行时无法找到的类:

public class CategoryParcel implements Parcelable{

private Long id;
private int icon;
private int category_resource;
private String categories;
private String note;
private Integer price;
private Integer quantity;
private String url;

public CategoryParcel(Parcel in){
    id = in.readLong();
    category_resource = in.readInt();
    categories = in.readString();
    note = in.readString();
    price = in.readInt();
    quantity = in.readInt();
    icon = in.readInt();
    url = in.readString();
}

public CategoryParcel(){}

public CategoryParcel(Long id, String categories, String note, int price, int quantity, int icon){
    this.id = id;

    this.categories = categories;
    this.note = note;
    this.price = price;
    this.quantity = quantity;
    this.icon = icon;
}

public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}

public int getCategory_resource() {
    return category_resource;
}

public void setCategory_resource(int category_resource) {
    this.category_resource = category_resource;
}

public String getCategories() {
    return categories;
}

public void setCategories(String categories) {
    this.categories = categories;
}

public String getNote() {
    return note;
}

public void setNote(String note) {
    this.note = note;
}

public Integer getPrice() {
    return price;
}

public void setPrice(Integer price) {
    this.price = price;
}

public Integer getQuantity() {
    return quantity;
}

public void setQuantity(Integer quantity) {
    this.quantity = quantity;
}

public int getIcon() {
    return icon;
}

public void setIcon(int icon) {
    this.icon = icon;
}

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


@Override
public void writeToParcel(Parcel parcel, int i) {
    parcel.writeLong(id);
    parcel.writeInt(category_resource);
    parcel.writeString(categories);
    parcel.writeString(note);
    parcel.writeInt(price);
    parcel.writeInt(quantity);
    parcel.writeInt(icon);
}

public static final Parcelable.Creator<CategoryParcel> CREATOR = new Parcelable.Creator<CategoryParcel>()
{
    public CategoryParcel createFromParcel(Parcel in)
    {
        return new CategoryParcel(in);
    }
    public CategoryParcel[] newArray(int size)
    {
        return new CategoryParcel[size];
    }
};

错误指向这一行:

public static final Parcelable.Creator CREATOR = new Parcelable.Creator()

如果您建议我可以分享更多详细信息。 我不知道我在这里做错了什么。

感谢阅读。 沙山

最佳答案

我解决了这个问题,这个和

有关

compile 'com.android.support:multidex:1.0.1'

最近谷歌发布了这个api来支持低版本的android。

要检查三件事:

  1. build.gradle 中的依赖

{ compile 'com.android.support:multidex:1.0.1' }

  1. 在build.gradle中添加defaultConfig

defaultConfig { multiDexEnabled true }

  1. 在AndroidManifest.xml文件中添加
 <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.android.multidex.myapplication">
        <application
            ...
            android:name="android.support.multidex.MultiDexApplication">
            ...
        </application>
    </manifest>

在我的例子中,我忘了添加第 3 点。

现在它工作正常并且可以在所有预期的设备上工作。

谢谢, 沙尚克普拉塔普

关于android - 找不到指向 Parcelable 的运行时错误 NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33612890/

相关文章:

Android 主题文本颜色与警报对话框标题颜色冲突

java - android webView 中的 ScrollView 不显示键盘

android - 如何在 "TextInputLayout"的右端动态添加一个 drawable?

visual-studio - 可以创建输出类型为 "none"的 Visual Studio 项目吗?

android - 使用 Matrix.setPolyToPoly 在位图上选择一个有 4 个点的区域

android - 如何以编程方式退出android应用程序

visual-studio - Visual Studio 解决方案中的常用文件

visual-studio - Visual Studio : Add existing folder(s) to project

c# - 您什么时候决定将大型项目拆分成较小的项目?

module - 模块化代码在 Go 中是如何工作的?