2011-07-28 16 views
7

Wartości są coraz przekazywane i wykonywanie odbywa się poprawnie, ale widzę, że są one wyrzucane w logcat i chcę je wyeliminować, sprawdziłem starsze fora, ale nic konkretnego. delegowania poniżej mojego kodu, proszę dać mi znać, dlaczego ten problem występujeandroid.os.BadParcelableException: ClassNotFoundException po unmarshalling: wyjątek

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

wyjątek, który jest wielokrotnie wyrzucane jest: ale to nie utrudniają realizację

: 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

udało Ci się znaleźć rozwiązanie bez użycia serializacji? – bencallis

+0

Możliwy duplikat ["BadParcelableException: ClassNotFoundException przy unmarshalling " podczas korzystania z metody Parcel.read z argumentem ClassLoader jako] (http://stackoverflow.com/questions/18126249/badparcelableexception-classnotfoundexception-when-unmarshalling-myclass-wh) – Flow

Odpowiedz

-7

W końcu używam serialization, więc nie otrzymuję tego wyjątku. Serializuję konwertowanie obiektu na tablicę bajtów, przechowuję ją, a następnie przekazuję w sprawdzaniu PendingIntent.

Jestem pewien, że to zwiększa nad głową, ale nie wydaje się wpływać na pracę .W tym przypadku, gdy alarmy uzyskać wyzwolone nie widzę żadnego wyjątku

+1

Nie jest to bardzo użyteczne rozwiązanie, ponieważ można pominąć użycie 'Parceli' i zamiast tego użyć' Serializable'. – Melllvar

+1

Nie powinieneś polegać na work arounds raczej znaleźć rozwiązanie, które działa lepiej. – Varundroid

4

myślę, że to zostanie odebrane przez jesteś tutaj: Problem unmarshalling parcelables.

Zasadniczo należy ustawić moduł ładujący klasy, ponieważ usługa AlarmManagerService jest oddzielnym procesem systemu operacyjnego.

+0

U oznacza to, że ta linia wyrzuca błąd source.readList (pollingIntervalArray, Integer.class.getClassLoader()); Nie widzę żadnego innego miejsca, w którym program ładujący klasy zostałby zaliczony lub musi zostać przekazany ??? – Kavitha

+0

Nie. Nawet nie dostajesz się do tej linii klasy ClassNotFoundException (na podstawie podanego śladu stosu). Nie jesteś sam, próbując wysłać paczkę za pomocą PendingIntent: http://stackoverflow.com/questions/2307476/classnotfoundexception-when-using-custom-parcelable/2307764#2307764 – Jason

+0

Ups ... powróć za wcześnie. Problem polega na tym, że program AlarmManager nie używa modułu ładującego klasy do deserializacji obiektu PendingIntent, aby nie miał dostępu do klasy ExecutionInfo. Niestety, wygląda na to, że możesz potrzebować alternatywnej metody serializacji. Jedną z możliwości byłoby samodzielne utworzenie działki ('Parcel paczk = Parcel.obtain()'), przekształcenie jej do postaci szeregowej ('infoObject.writeToParcel (działka, 0)'), pobranie tablicy bajtów ('byte [] rawParcel = paczkę. marshall() ') i wstaw tę tablicę bajtów do twojego pakietu. Po drugiej stronie musiałbyś użyć Parcel.unmarshall(), a następnie użyć konstruktora. – Jason

Powiązane problemy