Serialise/Deserialise List<String>
===

I was to save an arraylist of strings into 1 column in the local database. I am having some problems doing this. Can somebody tell me where I am going wrong...

    private String serializeArray(List<String> array) {
        try {
            ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(bytesOut);
            oos.writeObject(array);
            oos.flush();
            oos.close();
            return Base64.encodeToString(bytesOut.toByteArray(), Base64.NO_WRAP);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    private ArrayList<String> deserializeArray(String string) {
        Log.d("USERDAO", string);
        try {
            ByteArrayInputStream bytesIn = new ByteArrayInputStream(Base64.decode(string, Base64.NO_WRAP));
            ObjectInputStream ois = new ObjectInputStream(bytesIn);
            return (ArrayList<String>) ois.readObject();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }


I am getting a null pointer exception when returning the Arraylist on deserialise array. The serialiseArray method does return a string however I am not sure if it is correct.


0

> 7-20 08:35:49.035: W/System.err(564): java.lang.NullPointerException
> 07-20 08:35:49.055: W/System.err(564): 	at
> net.doo.Tags.UserTag.setDropboxFolders(UserTag.java:156) 07-20
> 08:35:49.055: W/System.err(564): 	at
> net.doo.localdb.dao.UserDAO.cursorToObject(UserDAO.java:36) 07-20
> 08:35:49.055: W/System.err(564): 	at
> net.doo.ui.DooActivity.onCreate(DooActivity.java:84) 07-20
> 08:35:49.055: W/System.err(564): 	at
> android.app.Activity.performCreate(Activity.java:4562) 07-20
> 08:35:49.055: W/System.err(564): 	at
> android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
> 07-20 08:35:49.055: W/System.err(564): 	at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
> 07-20 08:35:49.055: W/System.err(564): 	at
> android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
> 07-20 08:35:49.055: W/System.err(564): 	at
> android.app.ActivityThread.access$600(ActivityThread.java:128) 07-20
> 08:35:49.055: W/System.err(564): 	at
> android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
> 07-20 08:35:49.055: W/System.err(564): 	at
> android.os.Handler.dispatchMessage(Handler.java:99) 07-20
> 08:35:49.055: W/System.err(564): 	at
> android.os.Looper.loop(Looper.java:137) 07-20 08:35:49.065:
> W/System.err(564): 	at
> android.app.ActivityThread.main(ActivityThread.java:4514) 07-20
> 08:35:49.065: W/System.err(564): 	at
> java.lang.reflect.Method.invokeNative(Native Method) 07-20
> 08:35:49.065: W/System.err(564): 	at
> java.lang.reflect.Method.invoke(Method.java:511) 07-20 08:35:49.065:
> W/System.err(564): 	at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
> 07-20 08:35:49.065: W/System.err(564): 	at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760) 07-20
> 08:35:49.065: W/System.err(564): 	at
> dalvik.system.NativeStart.main(Native Method)

