Hi,
I've tried several ways to get it work but the only way I found is to
serialize all members of the class:
public void writeIt(String filename) throws IOException {
FileOutputStream fos = openFileOutput(filename,
MODE_WORLD_WRITEABLE);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeInt(this.i);
oos.writeDouble(this.d);
oos.writeChars(this.s);
oos.close();
fos.close();
}
I know that this is not the way but ...
Best Regards: Chechy
On Feb 10, 11:55 am, DaRolla <[email protected]> wrote:
> hi,
>
> I get nuts on this, who can help?
>
> package de.test;
>
> import java.io.FileOutputStream;
> import java.io.IOException;
> import java.io.ObjectOutputStream;
> import java.io.Serializable;
>
> import android.app.Activity;
> import android.os.Bundle;
> import android.util.Log;
> import android.widget.TextView;
>
> public class SerialisiereAndroidActivity extends Activity {
>
> @Override
> public void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> setContentView(R.layout.main);
>
> try {
> Serialisiere pi = new Serialisiere(3, Math.PI, "pi");
> ((TextView) findViewById(R.id.tv1)).setText("Serialisiere:
> " +
> pi.toString());
> pi.writeIt("pi.ser");
> }
> catch( Exception e) {
> Log.d( "SerialisiereAndroidActivity", e.toString() );
> }
> }
>
> public class Serialisiere implements Serializable {
>
> private static final long serialVersionUID =
> -3922493985071195239L;
>
> private int i;
> private double d;
> private String s;
>
> public Serialisiere(int i, double d, String s) {
> this.i = i;
> this.d = d;
> this.s = s;
> }
>
> public void writeIt(String filename) throws IOException {
> FileOutputStream fos = openFileOutput(filename,
> MODE_WORLD_WRITEABLE);
> ObjectOutputStream oos = new ObjectOutputStream(fos);
> oos.writeObject(Serialisiere.this);
> oos.close();
> fos.close();
> }
>
> @Override
> public String toString() {
> return "i=" + i + " d=" + d + " s=" + s;
> }
> }
>
> }
>
> the problem is:
>
> oos.writeObject(Serialisiere.this);
>
> this throws an java.io.NotSerializableException.
>
> who can help me on this?
>
> greetings,
> darolla
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---