Custom ListFragment Getting NullPointer Exception
<p>I am trying to implement List fragment with custom listview. While implementation i am getting below error in my logcat. And i am trying to get the Listview in my fragment onCreateView() like this </p>

<pre><code>ArrayListFragment list = new ArrayListFragment();
            getActivity().getSupportFragmentManager().beginTransaction().add(android.R.id.content,list).commit();
</code></pre>

<p>I am not getting what is wrong with it.</p>

<p>and my custom listfragment class is :-</p>

<pre><code>    public static class ArrayListFragment extends ListFragment implements OnClickListener{

        PairWithSensorFragment mPairWithSensorFragment = new PairWithSensorFragment();
        String[] arrayValues = {"Android", "BlackBerry", "iPhone", "Windows", "linuxPhone"};

         @Override
          public void onActivityCreated(Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);

            ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(getActivity(),
                    R.layout.pairwithsensor_listrow, android.R.id.text1, arrayValues);
            setListAdapter(adapter);

           /* ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(getActivity(),
                    android.R.layout.simple_list_item_1, arrayValues);
                setListAdapter(adapter);*/

          }

          @Override
          public void onListItemClick(ListView l, View v, int position, long id) {
            // Do something with the data
              Toast.makeText( getActivity().getBaseContext()  ,  arrayValues[position]+" "+"Clicked " , Toast.LENGTH_SHORT).show();

          }
}
</code></pre>

<p>pairwithsensor_listrow.xml:-</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:orientation="vertical"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:id="@+id/linear_layout"&gt;

    &lt;TextView
        android:id="@+id/tv_pairwithsensor_sensorid"
        android:layout_width="200dp"
        android:layout_height="wrap_content" 
        android:layout_margin="5dp"
        android:layout_alignParentLeft="true"&gt;
    &lt;/TextView&gt;

    &lt;EditText
        android:id="@+id/edt_pairwithsensor_sensorName"
        android:layout_width="200dp"
        android:layout_height="wrap_content" 
        android:layout_margin="5dp" 
        android:layout_toRightOf="@id/tv_pairwithsensor_sensorid"
        android:hint="@string/please_enter_value"&gt;
    &lt;/EditText&gt;

    &lt;Button
        android:id="@+id/btn_pairwithsensor_pair"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp" 
        android:layout_alignParentRight="true"
        android:text="@string/PairwithSensor_pairButton"/&gt;


&lt;/RelativeLayout&gt;
</code></pre>

<p><strong>Logcat</strong> </p>

<pre><code>    02-25 10:22:22.870: E/AndroidRuntime(10247): FATAL EXCEPTION: main
    02-25 10:22:22.870: E/AndroidRuntime(10247): java.lang.NullPointerException
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:392)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.widget.AbsListView.obtainView(AbsListView.java:2033)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.widget.ListView.makeAndAddView(ListView.java:1772)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.widget.ListView.fillDown(ListView.java:672)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.widget.ListView.fillFromTop(ListView.java:732)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.widget.ListView.layoutChildren(ListView.java:1625)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.widget.AbsListView.onLayout(AbsListView.java:1863)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.view.View.layout(View.java:11282)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.view.View.layout(View.java:11282)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.view.View.layout(View.java:11282)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.view.View.layout(View.java:11282)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.view.View.layout(View.java:11282)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.view.View.layout(View.java:11282)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.view.View.layout(View.java:11282)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1514)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2467)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.os.Handler.dispatchMessage(Handler.java:99)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.os.Looper.loop(Looper.java:137)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at android.app.ActivityThread.main(ActivityThread.java:4424)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at java.lang.reflect.Method.invokeNative(Native Method)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at java.lang.reflect.Method.invoke(Method.java:511)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    02-25 10:22:22.870: E/AndroidRuntime(10247):    at dalvik.system.NativeStart.main(Native Method)
</code></pre>
