I am doing this exercise at [CodeLearn](<http://www.codelearn.org/android-tutorial/twitter/9/local-storage-writing-to-file-example>"Android Tutorial") and it seems that maybe I am doing something wrong and am not able to get the array to write to ObjectOutputStream. There seems to be a null pointer exception. 

```
package com.arvisapps.aryansh.encryptit;

import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;

public class TweetListActivity extends ListActivity
{
    private ArrayAdapter tweetItemArrayAdapter;
    private List<Tweet> tweets;
    public Context ctx;
    public FileOutputStream fos;
    private static final String TWEETS_CACHE_FILE = "HEADER_BODY.ser";

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tweet_list);

    tweets = new ArrayList<Tweet>();
    for(int i = 0; i < 20 ; i++)
    {
        Tweet tweet = new Tweet();
        tweet.setTitle("Header #" + i);
        Log.d("Fuck Me", "Title captured " + tweet.getTitle());
        tweet.setBody("Body text #" + i);
        tweets.add(tweet);

        try
        {
            fos = ctx.openFileOutput(TWEETS_CACHE_FILE, Context.MODE_PRIVATE);
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(tweets);
            Log.d("File Testing", "Successfully written to file");
            oos.close();
            fos.close();
        }

        catch (Exception e)
        {
            e.printStackTrace();
            Log.d("File Testing", "Error writing tweets", e);
        }
    }

    tweetItemArrayAdapter = new TweetAdapter(this, tweets);
    setListAdapter(tweetItemArrayAdapter);
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id)
{
    Intent intent = new Intent(this, TweetDetailActivity.class);
    startActivity(intent);
}

}

```

In the log it always shows that there is an error in writing tweets to file.

And here's the error log: 

```
    12-25 17:46:20.158    6285-6285/com.arvisapps.aryansh.encryptit E/File Testing﹕ Error writing tweets
java.lang.NullPointerException
        at com.arvisapps.aryansh.encryptit.TweetListActivity.onCreate(TweetListActivity.java:43)
        at android.app.Activity.performCreate(Activity.java:5231)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2264)
        at android.app.ActivityThread.access$800(ActivityThread.java:144)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5139)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
        at dalvik.system.NativeStart.main(Native Method)

```