ArrayAdapter for FragmentList crashes applications
<p>This is my code for an android application:</p>

<pre><code>public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    //Attempting to set the Fragment
    System.err.println("Starting");
    FragmentManager fm = getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    System.err.println("Adding the fragment");
    FileBrowser fb = new FileBrowser();
    ft.add(R.id.flFBrowser,fb);
    ft.commit();
    System.err.println("Done");

    fb.test();
}
</code></pre>

<p>Where the file browser only has this:</p>

<pre><code>public void test(){
    System.err.println("Entre a test!!!");
    String[] MyList = {"Hello","world","of","the","lists"};
    System.err.println("File Row ID" + Integer.toString(R.layout.file_row));
    ArrayAdapter&lt;String&gt; aa = new ArrayAdapter&lt;String&gt;(getActivity(), R.layout.file_row, MyList);
    //setListAdapter(aa);       
}
</code></pre>

<p>The thing is if I comment the ArrayAdapter constructor the program does not crash If I uncomment it, it crashes with the following error:</p>

<pre><code>06-11 10:12:38.150: ERROR/AndroidRuntime(4804): FATAL EXCEPTION: main
06-11 10:12:38.150: ERROR/AndroidRuntime(4804): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ccr/com.ccr.Main}: java.lang.NullPointerException
06-11 10:12:38.150: ERROR/AndroidRuntime(4804):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1748)
06-11 10:12:38.150: ERROR/AndroidRuntime(4804):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1764)
06-11 10:12:38.150: ERROR/AndroidRuntime(4804):     at android.app.ActivityThread.access$1500(ActivityThread.java:122)
06-11 10:12:38.150: ERROR/AndroidRuntime(4804):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1002)
06-11 10:12:38.150: ERROR/AndroidRuntime(4804):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-11 10:12:38.150: ERROR/AndroidRuntime(4804):     at android.os.Looper.loop(Looper.java:132)
06-11 10:12:38.150: ERROR/AndroidRuntime(4804):     at android.app.ActivityThread.main(ActivityThread.java:4025)
06-11 10:12:38.150: ERROR/AndroidRuntime(4804):     at java.lang.reflect.Method.invokeNative(Native Method)
06-11 10:12:38.150: ERROR/AndroidRuntime(4804):     at java.lang.reflect.Method.invoke(Method.java:491)
06-11 10:12:38.150: ERROR/AndroidRuntime(4804):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
06-11 10:12:38.150: ERROR/AndroidRuntime(4804):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
06-11 10:12:38.150: ERROR/AndroidRuntime(4804):     at dalvik.system.NativeStart.main(Native Method)
06-11 10:12:38.150: ERROR/AndroidRuntime(4804): Caused by: java.lang.NullPointerException
06-11 10:12:38.150: ERROR/AndroidRuntime(4804):     at android.widget.ArrayAdapter.init(ArrayAdapter.java:314)
06-11 10:12:38.150: ERROR/AndroidRuntime(4804):     at android.widget.ArrayAdapter.&lt;init&gt;(ArrayAdapter.java:128)
06-11 10:12:38.150: ERROR/AndroidRuntime(4804):     at com.ccr.FileBrowser.test(FileBrowser.java:13)
06-11 10:12:38.150: ERROR/AndroidRuntime(4804):     at com.ccr.Main.onCreate(Main.java:24)
06-11 10:12:38.150: ERROR/AndroidRuntime(4804):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
06-11 10:12:38.150: ERROR/AndroidRuntime(4804):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1712)
06-11 10:12:38.150: ERROR/AndroidRuntime(4804):     ... 11 more
</code></pre>

<p>Does any one have any Idea what I could be doing wrong?</p>

<p>Thanks for any help!</p>

<p>UPDATE:</p>

<p>The problem seems to be specifically that getActivity returns null?
Any Idea why this is?</p>
