java应用程序在按下home/recent按钮打开微调器时崩溃

0ejtzxu1  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(350)

我的应用程序上有一个微调器,当微调器打开,然后按下home或recent按钮时,它会导致应用程序崩溃
正在使用的可搜索微调器是https://github.com/miteshpithadiya/searchablespinner
这就是我困扰我很久的错误

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.ioksupervisor.ats, PID: 8972
    java.lang.RuntimeException: Parcel: unable to marshal value Select Material
        at android.os.Parcel.writeValue(Parcel.java:1781)
        at android.os.Parcel.writeList(Parcel.java:934)
        at android.os.Parcel.writeValue(Parcel.java:1728)
        at android.os.Parcel.writeArrayMapInternal(Parcel.java:846)
        at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1542)
        at android.os.Bundle.writeToParcel(Bundle.java:1232)
        at android.os.Parcel.writeBundle(Parcel.java:886)
        at android.app.FragmentState.writeToParcel(FragmentState.java:120)
        at android.os.Parcel.writeTypedArray(Parcel.java:1471)
        at android.app.FragmentManagerState.writeToParcel(FragmentManager.java:599)
        at android.os.Parcel.writeParcelable(Parcel.java:1800)
        at android.os.Parcel.writeValue(Parcel.java:1706)
        at android.os.Parcel.writeArrayMapInternal(Parcel.java:846)
        at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1542)
        at android.os.Bundle.writeToParcel(Bundle.java:1232)
        at android.app.IActivityManager$Stub$Proxy.activityStopped(IActivityManager.java:4687)
        at android.app.ActivityThread$StopInfo.run(ActivityThread.java:4031)
        at android.os.Handler.handleCallback(Handler.java:790)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6626)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)

填充微调器

public void populateSpinner(HashMap<Integer, String> map) {

        List<StringWithTag> arrayList = new ArrayList<StringWithTag>();
        arrayList.add(new StringWithTag("Select Material", 0));

// Hash map contains the key-value pair of the options of the spinner
        for (Map.Entry<Integer, String> entry : map.entrySet()) {
            Integer key = Integer.parseInt(String.valueOf(entry.getKey()));
            String value = entry.getValue();
            arrayList.add(new StringWithTag(value, key));
        }

        ArrayAdapter<StringWithTag> arrayAdapter = new ArrayAdapter<StringWithTag>(MainActivity.this, android.R.layout.simple_spinner_item, arrayList);
        arrayAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
    }

带标记类的字符串

public class StringWithTag {

    public String string;
    public Object tag;

    public StringWithTag(String string, Object tag) {
        this.string = string;
        this.tag = tag;
    }

    @Override
    public String toString() {
        return string;
    }
}

提前谢谢

c0vxltue

c0vxltue1#

在实现serializable to stringwithtag still之后,请给出另一个错误

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.ioksupervisor.ats, PID: 21320
    java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.toptoche.searchablespinnerlibrary.SearchableSpinner)

这是通过扩展和创建一个自定义的可搜索微调器来解决的。其中的链接是https://github.com/miteshpithadiya/searchablespinner/issues/55#issuecomment-362430652

相关问题