我正在尝试将 Data.class 的自写对象“数据”传递给具有主活动“主屏幕”的新创建的活动“SettingsScreen”
数据:
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;
}
MainScreen 中的方法:
public void optionsButton(View v)
{
Intent intent = new Intent(this, SettingsScreen.class);
intent.putExtra("data", data); // IT CRASHES HERE, data Object is NOT NULL
startActivity(intent);
}
最后是 SettingsScreen 的 OnCreate 方法:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings_screen);
data = (Data) getIntent().getSerializableExtra("data");
}
这是 LogCat 输出:
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) to 9.017MB for 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) to 10.169MB for 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 with 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: Could not execute method of the activity
05-14 09:35:10.401: E/AndroidRuntime(1623): at android.view.View$1.onClick(View.java:3591)
05-14 09:35:10.401: E/AndroidRuntime(1623): at android.view.View.performClick(View.java:4084)
05-14 09:35:10.401: E/AndroidRuntime(1623): at android.view.View$PerformClick.run(View.java:16966)
05-14 09:35:10.401: E/AndroidRuntime(1623): at android.os.Handler.handleCallback(Handler.java:615)
05-14 09:35:10.401: E/AndroidRuntime(1623): at android.os.Handler.dispatchMessage(Handler.java:92)
05-14 09:35:10.401: E/AndroidRuntime(1623): at android.os.Looper.loop(Looper.java:137)
05-14 09:35:10.401: E/AndroidRuntime(1623): at android.app.ActivityThread.main(ActivityThread.java:4745)
05-14 09:35:10.401: E/AndroidRuntime(1623): at java.lang.reflect.Method.invokeNative(Native Method)
05-14 09:35:10.401: E/AndroidRuntime(1623): at java.lang.reflect.Method.invoke(Method.java:511)
05-14 09:35:10.401: E/AndroidRuntime(1623): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
05-14 09:35:10.401: E/AndroidRuntime(1623): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-14 09:35:10.401: E/AndroidRuntime(1623): at 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): at java.lang.reflect.Method.invokeNative(Native Method)
05-14 09:35:10.401: E/AndroidRuntime(1623): at java.lang.reflect.Method.invoke(Method.java:511)
05-14 09:35:10.401: E/AndroidRuntime(1623): at 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): at android.os.Parcel.writeSerializable(Parcel.java:1279)
05-14 09:35:10.401: E/AndroidRuntime(1623): at android.os.Parcel.writeValue(Parcel.java:1233)
05-14 09:35:10.401: E/AndroidRuntime(1623): at android.os.Parcel.writeMapInternal(Parcel.java:591)
05-14 09:35:10.401: E/AndroidRuntime(1623): at android.os.Bundle.writeToParcel(Bundle.java:1619)
05-14 09:35:10.401: E/AndroidRuntime(1623): at android.os.Parcel.writeBundle(Parcel.java:605)
05-14 09:35:10.401: E/AndroidRuntime(1623): at android.content.Intent.writeToParcel(Intent.java:6470)
05-14 09:35:10.401: E/AndroidRuntime(1623): at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1741)
05-14 09:35:10.401: E/AndroidRuntime(1623): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1411)
05-14 09:35:10.401: E/AndroidRuntime(1623): at android.app.Activity.startActivityForResult(Activity.java:3351)
05-14 09:35:10.401: E/AndroidRuntime(1623): at android.app.Activity.startActivityForResult(Activity.java:3312)
05-14 09:35:10.401: E/AndroidRuntime(1623): at android.app.Activity.startActivity(Activity.java:3522)
05-14 09:35:10.401: E/AndroidRuntime(1623): at android.app.Activity.startActivity(Activity.java:3490)
05-14 09:35:10.401: E/AndroidRuntime(1623): at 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): at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1364)
05-14 09:35:10.401: E/AndroidRuntime(1623): at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671)
05-14 09:35:10.401: E/AndroidRuntime(1623): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
05-14 09:35:10.401: E/AndroidRuntime(1623): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
05-14 09:35:10.401: E/AndroidRuntime(1623): at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:979)
05-14 09:35:10.401: E/AndroidRuntime(1623): at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:368)
05-14 09:35:10.401: E/AndroidRuntime(1623): at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1074)
05-14 09:35:10.401: E/AndroidRuntime(1623): at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1404)
05-14 09:35:10.401: E/AndroidRuntime(1623): at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671)
05-14 09:35:10.401: E/AndroidRuntime(1623): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
05-14 09:35:10.401: E/AndroidRuntime(1623): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
05-14 09:35:10.401: E/AndroidRuntime(1623): at 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