java - passing self writting Object via putExtra() -
i trying pass on selfwritten object "data" of data.class newly created activity "settingsscreen" main activity "mainscreen"
data:
public class data implements serializable { private string ende; private string anfang; private string protocol; private string urlkomplett; private string username; private string password; private string manufacturer; private string type; private string productnr; private string rfid; private int scanart; private sharedpreferences prefs; private mainscreen main; private editor edit; private connectivitymanager connmanager; }
method in mainscreen:
public void optionsbutton(view v) { intent intent = new intent(this, settingsscreen.class); intent.putextra("data", data); // crashes here, data object not null startactivity(intent); }
and oncreate-method of settingsscreen:
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_settings_screen); data = (data) getintent().getserializableextra("data"); }
and here logcat output:
05-14 09:35:04.040: e/trace(1623): error opening trace file: no such file or directory (2) 05-14 09:35:04.340: d/dalvikvm(1623): gc_for_alloc freed 41k, 9% free 7256k/7939k, paused 65ms, total 66ms 05-14 09:35:04.370: i/dalvikvm-heap(1623): grow heap (frag case) 9.017mb 1536016-byte allocation 05-14 09:35:04.560: d/dalvikvm(1623): gc_concurrent freed <1k, 8% free 8755k/9479k, paused 87ms+3ms, total 190ms 05-14 09:35:04.680: d/dalvikvm(1623): gc_for_alloc freed 0k, 8% free 8755k/9479k, paused 27ms, total 27ms 05-14 09:35:04.690: i/dalvikvm-heap(1623): grow heap (frag case) 10.169mb 1209856-byte allocation 05-14 09:35:04.870: d/dalvikvm(1623): gc_concurrent freed 0k, 8% free 9936k/10695k, paused 125ms+3ms, total 175ms 05-14 09:35:05.100: d/libegl(1623): loaded /system/lib/egl/libegl_emulation.so 05-14 09:35:05.191: d/(1623): hostconnection::get() new host connection established 0x2a13f270, tid 1623 05-14 09:35:05.223: d/libegl(1623): loaded /system/lib/egl/libglesv1_cm_emulation.so 05-14 09:35:05.230: d/libegl(1623): loaded /system/lib/egl/libglesv2_emulation.so 05-14 09:35:05.401: w/egl_emulation(1623): eglsurfaceattrib not implemented 05-14 09:35:05.410: d/openglrenderer(1623): enabling debug mode 0 05-14 09:35:07.715: w/egl_emulation(1623): eglsurfaceattrib not implemented 05-14 09:35:10.301: d/androidruntime(1623): shutting down vm 05-14 09:35:10.301: w/dalvikvm(1623): threadid=1: thread exiting uncaught exception (group=0x40a13300) 05-14 09:35:10.401: e/androidruntime(1623): fatal exception: main 05-14 09:35:10.401: e/androidruntime(1623): java.lang.illegalstateexception: not execute method of activity 05-14 09:35:10.401: e/androidruntime(1623): @ android.view.view$1.onclick(view.java:3591) 05-14 09:35:10.401: e/androidruntime(1623): @ android.view.view.performclick(view.java:4084) 05-14 09:35:10.401: e/androidruntime(1623): @ android.view.view$performclick.run(view.java:16966) 05-14 09:35:10.401: e/androidruntime(1623): @ android.os.handler.handlecallback(handler.java:615) 05-14 09:35:10.401: e/androidruntime(1623): @ android.os.handler.dispatchmessage(handler.java:92) 05-14 09:35:10.401: e/androidruntime(1623): @ android.os.looper.loop(looper.java:137) 05-14 09:35:10.401: e/androidruntime(1623): @ android.app.activitythread.main(activitythread.java:4745) 05-14 09:35:10.401: e/androidruntime(1623): @ java.lang.reflect.method.invokenative(native method) 05-14 09:35:10.401: e/androidruntime(1623): @ java.lang.reflect.method.invoke(method.java:511) 05-14 09:35:10.401: e/androidruntime(1623): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:786) 05-14 09:35:10.401: e/androidruntime(1623): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:553) 05-14 09:35:10.401: e/androidruntime(1623): @ dalvik.system.nativestart.main(native method) 05-14 09:35:10.401: e/androidruntime(1623): caused by: java.lang.reflect.invocationtargetexception 05-14 09:35:10.401: e/androidruntime(1623): @ java.lang.reflect.method.invokenative(native method) 05-14 09:35:10.401: e/androidruntime(1623): @ java.lang.reflect.method.invoke(method.java:511) 05-14 09:35:10.401: e/androidruntime(1623): @ android.view.view$1.onclick(view.java:3586) 05-14 09:35:10.401: e/androidruntime(1623): ... 11 more 05-14 09:35:10.401: e/androidruntime(1623): caused by: java.lang.runtimeexception: parcelable encountered ioexception writing serializable object (name = com.test.app.data) 05-14 09:35:10.401: e/androidruntime(1623): @ android.os.parcel.writeserializable(parcel.java:1279) 05-14 09:35:10.401: e/androidruntime(1623): @ android.os.parcel.writevalue(parcel.java:1233) 05-14 09:35:10.401: e/androidruntime(1623): @ android.os.parcel.writemapinternal(parcel.java:591) 05-14 09:35:10.401: e/androidruntime(1623): @ android.os.bundle.writetoparcel(bundle.java:1619) 05-14 09:35:10.401: e/androidruntime(1623): @ android.os.parcel.writebundle(parcel.java:605) 05-14 09:35:10.401: e/androidruntime(1623): @ android.content.intent.writetoparcel(intent.java:6470) 05-14 09:35:10.401: e/androidruntime(1623): @ android.app.activitymanagerproxy.startactivity(activitymanagernative.java:1741) 05-14 09:35:10.401: e/androidruntime(1623): @ android.app.instrumentation.execstartactivity(instrumentation.java:1411) 05-14 09:35:10.401: e/androidruntime(1623): @ android.app.activity.startactivityforresult(activity.java:3351) 05-14 09:35:10.401: e/androidruntime(1623): @ android.app.activity.startactivityforresult(activity.java:3312) 05-14 09:35:10.401: e/androidruntime(1623): @ android.app.activity.startactivity(activity.java:3522) 05-14 09:35:10.401: e/androidruntime(1623): @ android.app.activity.startactivity(activity.java:3490) 05-14 09:35:10.401: e/androidruntime(1623): @ com.test.app.mainscreen.optionsbutton(mainscreen.java:140) 05-14 09:35:10.401: e/androidruntime(1623): ... 14 more 05-14 09:35:10.401: e/androidruntime(1623): caused by: java.io.notserializableexception: android.net.connectivitymanager 05-14 09:35:10.401: e/androidruntime(1623): @ java.io.objectoutputstream.writenewobject(objectoutputstream.java:1364) 05-14 09:35:10.401: e/androidruntime(1623): @ java.io.objectoutputstream.writeobjectinternal(objectoutputstream.java:1671) 05-14 09:35:10.401: e/androidruntime(1623): @ java.io.objectoutputstream.writeobject(objectoutputstream.java:1517) 05-14 09:35:10.401: e/androidruntime(1623): @ java.io.objectoutputstream.writeobject(objectoutputstream.java:1481) 05-14 09:35:10.401: e/androidruntime(1623): @ java.io.objectoutputstream.writefieldvalues(objectoutputstream.java:979) 05-14 09:35:10.401: e/androidruntime(1623): @ java.io.objectoutputstream.defaultwriteobject(objectoutputstream.java:368) 05-14 09:35:10.401: e/androidruntime(1623): @ java.io.objectoutputstream.writehierarchy(objectoutputstream.java:1074) 05-14 09:35:10.401: e/androidruntime(1623): @ java.io.objectoutputstream.writenewobject(objectoutputstream.java:1404) 05-14 09:35:10.401: e/androidruntime(1623): @ java.io.objectoutputstream.writeobjectinternal(objectoutputstream.java:1671) 05-14 09:35:10.401: e/androidruntime(1623): @ java.io.objectoutputstream.writeobject(objectoutputstream.java:1517) 05-14 09:35:10.401: e/androidruntime(1623): @ java.io.objectoutputstream.writeobject(objectoutputstream.java:1481) 05-14 09:35:10.401: e/androidruntime(1623): @ android.os.parcel.writeserializable(parcel.java:1274) 05-14 09:35:10.401: e/androidruntime(1623): ... 26 more 05-14 09:35:12.700: i/process(1623): sending signal. pid: 1623 sig: 9
in order serialiable class must:
- implements
serializable
interface - every member inside class must implements
serializable
if 2 requirements not meet class can not serialized.
in case private connectivitymanager connmanager;
not implements serializable
can not serialized. causing exception. if want keep inside class , want serialize class can add transient keyoword
private transient connectivitymanager connmanager;
Comments
Post a Comment