2011-07-28 130 views
7

值正在传递并执行正确,但我看到这些被扔在logcat中,我想消除这些,我检查了旧的论坛,但没有具体。我是下面张贴我的代码,请不要让我知道为什么会变成这样的问题发生,这被抛出反复是android.os.BadParcelableException:解组时发生ClassNotFoundException:异常

public class ExecutionInfo implements Parcelable 
{ 

    private int offSet; 

    private List<Integer> pollingIntervalArray = new ArrayList<Integer>(); 

    private List<String> commandLst= new ArrayList<String>(); 

    private int repeatCount; 

    private int executorId; 

    private int processType; 


    public ExecutionInfo() 
    { 

    } 

    public ExecutionInfo(Parcel source) 
    { 
     offSet = source.readInt(); 
     repeatCount = source.readInt(); 
     executorId = source.readInt(); 
     processType = source.readInt(); 
     source.readStringList(commandLst); 
     source.readList(pollingIntervalArray, Integer.class.getClassLoader()); 
    } 

    public int getOffSet() 
    { 
     return offSet; 
    } 

    public void setOffSet(int offSet) 
    { 
     this.offSet = offSet; 
    } 

    public List<Integer> getInterval() 
    { 
     return pollingIntervalArray; 
    } 

    public void setInterval(List<Integer> pollingIntervalVec) 
    { 
     this.pollingIntervalArray = pollingIntervalVec; 
    } 

    public List<String> getCommandLst() 
    { 
     return commandLst; 
    } 

    public void setCommands(String command) 
    { 
     commandLst.add(command); 
    } 

    public int getRepeatCount() 
    { 
     return repeatCount; 
    } 

    public void setRepeatCount(int repeatCount) 
    { 
     this.repeatCount = repeatCount; 
    } 

    public int getExecutorId() 
    { 
     return executorId; 
    } 

    public void setExecutorId(int executorId) 
    { 
     this.executorId = executorId; 
    } 

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

    @Override 
    public void writeToParcel(Parcel dest, int flags) 
    { 

      dest.writeInt(offSet); 
      dest.writeInt(repeatCount); 
      dest.writeInt(executorId); 
      dest.writeInt(processType); 
      dest.writeStringList(commandLst); 
      dest.writeList(pollingIntervalArray); 
    } 

    public static final Parcelable.Creator<ExecutionInfo> CREATOR = new Parcelable.Creator<ExecutionInfo>() 
    { 
     public ExecutionInfo createFromParcel(Parcel in) 
     { 
      return new ExecutionInfo(in); 
     } 

     public ExecutionInfo[] newArray(int size) 
     { 
      return new ExecutionInfo[size]; 
     } 
    }; 

    public int getProcessType() 
    { 
     return processType; 
    } 

    public void setProcessType(int processType) 
    { 
     this.processType = processType; 
    } 
} 

例外:但这并不妨碍执行

: com.seven.superapptwitter.xmlHandler.ExecutionInfo 
07-27 16:52:11.418: WARN/Intent(2458): Failure filling in extras 
07-27 16:52:11.418: WARN/Intent(2458): android.os.BadParcelableException: ClassNotFoundException when unmarshalling: com.seven.superapptwitter.xmlHandler.ExecutionInfo 
07-27 16:52:11.418: WARN/Intent(2458):  at android.os.Parcel.readParcelable(Parcel.java:1883) 
07-27 16:52:11.418: WARN/Intent(2458):  at android.os.Parcel.readValue(Parcel.java:1771) 
07-27 16:52:11.418: WARN/Intent(2458):  at android.os.Parcel.readMapInternal(Parcel.java:2008) 
07-27 16:52:11.418: WARN/Intent(2458):  at android.os.Bundle.unparcel(Bundle.java:208) 
07-27 16:52:11.418: WARN/Intent(2458):  at android.os.Bundle.putAll(Bundle.java:281) 
07-27 16:52:11.418: WARN/Intent(2458):  at android.content.Intent.fillIn(Intent.java:5127) 
07-27 16:52:11.418: WARN/Intent(2458):  at com.android.server.am.PendingIntentRecord.sendInner(PendingIntentRecord.java:195) 
07-27 16:52:11.418: WARN/Intent(2458):  at com.android.server.am.PendingIntentRecord.send(PendingIntentRecord.java:177) 
07-27 16:52:11.418: WARN/Intent(2458):  at android.app.PendingIntent.send(PendingIntent.java:400) 
07-27 16:52:11.418: WARN/Intent(2458):  at com.android.server.AlarmManagerService$AlarmThread.run(AlarmManagerService.java:680) 
+0

你设法找到不使用序列化的解决方案? – bencallis

+0

[使用具有ClassLoader作为参数的Parcel.read方法时,解组为时出现[“BadParcelableException:ClassNotFoundException异常]的可能重复](http://stackoverflow.com/questions/18126249/badparcelableexception-classnotfoundexception-when-unmarshalling-myclass-wh ) – Flow

回答

-7

好吧,最后我使用serialization,以便我不会得到这个例外。我序列化对象转换为字节数组存储它,然后通过PendingIntent检查传递它。

我相信这增加了头,但似乎并没有影响工作。在这种情况下,当警报被触发我看不出有任何异常

+1

不是一个非常有用的解决方案,因为您可以跳过使用'Parcelable'并使用'Serializable'来代替。 – Melllvar

+1

你不应该依靠工作而是找到一个更好的解决方案。 – Varundroid

4

我认为这是回答了你在这里:Problem unmarshalling parcelables

基本上你需要设置类加载器,因为AlarmManagerService是一个单独的OS进程。

+0

U的意思是,这一行是抛出错误source.readList(pollingIntervalArray,Integer.class.getClassLoader());我没有看到类加载器已通过或需要通过的其他任何地方? – Kavitha

+0

不可以。您甚至没有进入ClassNotFoundException的那一行(在您提供的堆栈跟踪中)。你并不孤单,试图通过PendingIntent发送一个parcelable:http://stackoverflow.com/questions/2307476/classnotfoundexception-when-using-custom-parcelable/2307764#2307764 – Jason

+0

哎呀...太快回击。问题是AlarmManager没有使用你的类加载器来反序列化PendingIntent,因此它无法访问你的ExecutionInfo类。不幸的是,它看起来好像你可能不得不使用另一种序列化方法。一种可能性是自己创建一个Parcel('Parcel parcel = Parcel.obtain()'),将其序列化('infoObject.writeToParcel(parcel,0)'),获取字节数组(byte [] rawParcel = parcel。 marshall()')并将该字节数组放入您的包中。另一方面,你必须使用Parcel.unmarshall(),然后使用构造函数 – Jason