07-14 11:58:28.160: WARN/Intent(1911): Failure filling in extras
07-14 11:58:28.160: WARN/Intent(1911): java.lang.RuntimeException: Parcelable encounteredClassNotFoundException reading a Serializable object (name = ams.gelato.api.TaskScheduler$Task)
07-14 11:58:28.160: WARN/Intent(1911): at android.os.Parcel.readSerializable(Parcel.java:1890)
07-14 11:58:28.160: WARN/Intent(1911): at android.os.Parcel.readValue(Parcel.java:1761)
07-14 11:58:28.160: WARN/Intent(1911): at android.os.Parcel.readMapInternal(Parcel.java:1947)
07-14 11:58:28.160: WARN/Intent(1911): at android.os.Bundle.unparcel(Bundle.java:169)
07-14 11:58:28.160: WARN/Intent(1911): at android.os.Bundle.putAll(Bundle.java:242)
07-14 11:58:28.160: WARN/Intent(1911): at android.content.Intent.fillIn(Intent.java:4853)
07-14 11:58:28.160: WARN/Intent(1911): at com.android.server.am.PendingIntentRecord.sendInner(PendingIntentRecord.java:194)
07-14 11:58:28.160: WARN/Intent(1911): at com.android.server.am.PendingIntentRecord.send(PendingIntentRecord.java:176)
07-14 11:58:28.160: WARN/Intent(1911): at android.app.PendingIntent.send(PendingIntent.java:400)
07-14 11:58:28.160: WARN/Intent(1911): at com.android.server.AlarmManagerService$AlarmThread.run(AlarmManagerService.java:645)
07-14 11:58:28.160: WARN/Intent(1911): Caused by: java.lang.ClassNotFoundException: ams.gelato.api.TaskScheduler$Task
07-14 11:58:28.160: WARN/Intent(1911): at java.lang.Class.classForName(Native Method)
07-14 11:58:28.160: WARN/Intent(1911): at java.lang.Class.forName(Class.java:237)
07-14 11:58:28.160: WARN/Intent(1911): at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:2604)
07-14 11:58:28.160: WARN/Intent(1911): at java.io.ObjectInputStream.readNewClassDesc(ObjectInputStream.java:1860)
07-14 11:58:28.160: WARN/Intent(1911): at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:840)
07-14 11:58:28.160: WARN/Intent(1911): at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:2080)
07-14 11:58:28.160: WARN/Intent(1911): at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:943)
07-14 11:58:28.160: WARN/Intent(1911): at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2299)
07-14 11:58:28.160: WARN/Intent(1911): at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2254)
07-14 11:58:28.160: WARN/Intent(1911): at android.os.Parcel.readSerializable(Parcel.java:1884)
07-14 11:58:28.160: WARN/Intent(1911): ... 9 more
07-14 11:58:28.160: WARN/Intent(1911): Caused by: java.lang.NoClassDefFoundError: ams.gelato.api.TaskScheduler$Task
07-14 11:58:28.160: WARN/Intent(1911): ... 19 more
07-14 11:58:28.160: WARN/Intent(1911): Caused by: java.lang.ClassNotFoundException: ams.gelato.api.TaskScheduler$Task in loader dalvik.system.PathClassLoader@4001b4f8
07-14 11:58:28.160: WARN/Intent(1911): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
07-14 11:58:28.160: WARN/Intent(1911): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
07-14 11:58:28.160: WARN/Intent(1911): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
07-14 11:58:28.160: WARN/Intent(1911): ... 19 more
尝试将可序列化对象传递给intent
时出现此异常package ams.gelato.api;
imports...
...
public class TaskScheduler implements ITaskScheduler{
List<Task> tasks = new ArrayList<Task>();
Context context = null;
Intent intent= null;
AlarmManager am = null;
public TaskScheduler(Context c){
context = c;
intent = new Intent(context,TaskReceiver.class);
am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
}
@Override
public boolean RunTaskAtTime(ITask _task, Date time) {
Intent newIntent = new Intent(intent);
newIntent.putExtra("task", new Task(_task));
am.set(AlarmManager.RTC_WAKEUP, time.getTime(), PendingIntent.getBroadcast(context, 0, newIntent, PendingIntent.FLAG_UPDATE_CURRENT));
return true;
}
public static class Task implements ITask,Serializable{
ITask task;
public Task(ITask t){
task = t;
}
@Override
public void runTask(){
}
}
这是我的taskscheduler的源代码。有问题的链接是; newIntent.putExtra(“任务”,新任务(_task)); 我不确定为什么会抛出这些异常,有人可以帮助我吗?
答案 0 :(得分:2)
如果您想传递Task的对象,您必须执行类似的操作
public class Task实现了Parcelable { 这里......实现方法 }
查看此示例
http://blog.cluepusher.dk/2009/10/28/writing-parcelable-classes-for-android/