Note that there are some explanatory texts on larger screens.

plurals
  1. POwhy does this simple serializable object throw NotSerializableException?
    primarykey
    data
    text
    <p>After getting no answer to my last question, I reformulated the thing to its simplest form. 1 button, 1 clicklistener, 1 serializable object and 1 subroutine to output the serializable object. This code is based on about 6-8 examples I found here on stackoverflow. And yet as simple as it is it still generates this error: W/System.err(228): java.io.NotSerializableException: serobj.testActivity So I challenge you, oh so wise code gurus: why does this code generate this error? And most importantly what do I do to fix it? The entire code followed by log ouput:</p> <pre><code>package serobj; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.io.Serializable; import ser.obj.R; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; public class testActivity extends Activity { /** Called when the activity is first created. */ public class Tester implements Serializable{ /** * */ private static final long serialVersionUID = 1L; public String frog; public Tester(){ frog="frog"; } } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button button1 = (Button) findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Testit(); } }); } public void Testit(){ Tester test = new Tester(); FileOutputStream fos; try { fos =openFileOutput("test.fyl", Context.MODE_WORLD_READABLE); Log.d("file open","..."); ObjectOutputStream oos = new ObjectOutputStream(fos); Log.d("ObjOutStr","..."); oos.writeObject(test); Log.d("tried wO","..."); // never gets here... oos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); Log.d ("filenotfound", "filenotfound"); }catch(IOException e){ e.printStackTrace(); Log.d("ioexception", "ioexception"); } } </code></pre> <p>}</p> <pre><code>03-17 04:40:02.691: D/file open(228): ... 03-17 04:40:02.701: D/ObjOutStr(228): ... 03-17 04:40:02.961: W/System.err(228): java.io.NotSerializableException: serobj.testActivity 03-17 04:40:02.971: W/System.err(228): at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1547) 03-17 04:40:02.971: W/System.err(228): at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1854) 03-17 04:40:02.971: W/System.err(228): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1696) 03-17 04:40:02.971: W/System.err(228): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1660) 03-17 04:40:02.971: W/System.err(228): at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:1153) 03-17 04:40:02.971: W/System.err(228): at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:420) 03-17 04:40:02.981: W/System.err(228): at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1251) 03-17 04:40:02.981: W/System.err(228): at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1587) 03-17 04:40:02.981: W/System.err(228): at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1854) 03-17 04:40:02.981: W/System.err(228): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1696) 03-17 04:40:02.981: W/System.err(228): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1660) 03-17 04:40:02.981: W/System.err(228): at serobj.testActivity.Testit(testActivity.java:50) 03-17 04:40:03.015: W/System.err(228): at serobj.testActivity$1.onClick(testActivity.java:37) 03-17 04:40:03.015: W/System.err(228): at android.view.View.performClick(View.java:2364) 03-17 04:40:03.015: W/System.err(228): at android.view.View.onTouchEvent(View.java:4179) 03-17 04:40:03.015: W/System.err(228): at android.widget.TextView.onTouchEvent(TextView.java:6541) 03-17 04:40:03.015: W/System.err(228): at android.view.View.dispatchTouchEvent(View.java:3709) 03-17 04:40:03.015: W/System.err(228): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 03-17 04:40:03.021: W/System.err(228): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 03-17 04:40:03.021: W/System.err(228): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 03-17 04:40:03.021: W/System.err(228): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 03-17 04:40:03.021: W/System.err(228): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 03-17 04:40:03.021: W/System.err(228): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659) 03-17 04:40:03.021: W/System.err(228): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107) 03-17 04:40:03.021: W/System.err(228): at android.app.Activity.dispatchTouchEvent(Activity.java:2061) 03-17 04:40:03.021: W/System.err(228): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643) 03-17 04:40:03.021: W/System.err(228): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691) 03-17 04:40:03.021: W/System.err(228): at android.os.Handler.dispatchMessage(Handler.java:99) 03-17 04:40:03.031: W/System.err(228): at android.os.Looper.loop(Looper.java:123) 03-17 04:40:03.031: W/System.err(228): at android.app.ActivityThread.main(ActivityThread.java:4363) 03-17 04:40:03.031: W/System.err(228): at java.lang.reflect.Method.invokeNative(Native Method) 03-17 04:40:03.031: W/System.err(228): at java.lang.reflect.Method.invoke(Method.java:521) 03-17 04:40:03.031: W/System.err(228): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 03-17 04:40:03.031: W/System.err(228): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 03-17 04:40:03.031: W/System.err(228): at dalvik.system.NativeStart.main(Native Method) 03-17 04:40:03.031: D/ioexception(228): ioexception 03-17 04:51:21.861: D/dalvikvm(56): threadid=15: bogus mon 1+0&gt;0; adjusting </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload