title: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getImportantForAccessibility()' on a null object reference
body: <p>I'm trying to put together a shopping list app, based on input fields, <code>ArrayList</code>, and <code>ListView</code>. The app will be based on <code>Fragments</code>. However, I have encountered a problem and I do not know how to solve it.</p>
  <p>I looked around on both Google and StackOverflow and I have found some information. However, I have not got it to work. Now I hope that I can get help with my code.</p>
  <p>I'm relatively inexperienced in Android development.</p>
  <p><strong>Main.java</strong></p>
  <pre><code>import java.util.ArrayList;
  
  import android.app.Fragment;
  import android.app.FragmentManager;
  import android.app.FragmentTransaction;
  import android.os.Bundle;
  import android.support.v4.app.FragmentActivity;
  import android.view.Menu;
  import android.view.MenuItem;
  
  public class Main extends FragmentActivity {
      
      ArrayList&lt;Detail&gt; items = new ArrayList&lt;Detail&gt;();
      FragmentManager FM;
      FragmentTransaction FT;
      Input input = new Input();
      
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          
          replaceFragment(R.id.container, input);
      }
  
      
      public void replaceFragment(int container, Fragment fragment){
          FM = getFragmentManager();
          FT = FM.beginTransaction();
          
          FT.replace(container, fragment);
          FT.commit();
      }
      
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
          if (id == R.id.action_settings) {
              return true;
          }
          return super.onOptionsItemSelected(item);
      }
  }
  </code></pre>
  <p><strong>ListAdapter.java</strong></p>
  <pre><code>public class ListAdapter extends BaseAdapter {
  
      Context context;
      ArrayList&lt;Detail&gt; items;
      
      public ListAdapter(Context context, ArrayList&lt;Detail&gt; items) {
          this.context = context;
          this.items = items;
      }
      
      @Override
      public int getCount() {
          return items.size();
      }
  
      @Override
      public Object getItem(int position) {
          return items.get(position);
      }
  
      @Override
      public long getItemId(int position) {
          return items.indexOf(getItem(position));
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          
          if(convertView == null){
              LayoutInflater lInflater = (LayoutInflater)context.getSystemService(
                      Activity.LAYOUT_INFLATER_SERVICE);
              
              convertView = lInflater.inflate(R.layout.list_row, null);       
          }
          
          TextView title = (TextView)convertView.findViewById(R.id.itemTitle);
          CheckBox done = (CheckBox)convertView.findViewById(R.id.itemDone);
          
          
          Detail detail_position = items.get(position);
          
          title.setText(detail_position.getTitle());
          done.setChecked(detail_position.isDone());
          
          return null;
      }
  }
  </code></pre>
  <p><strong>List.java</strong></p>
  <pre><code>import java.util.ArrayList;
  
  import android.app.ListFragment;
  import android.os.Bundle;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.AdapterView;
  import android.widget.AdapterView.OnItemClickListener;
  
  public class List extends ListFragment implements OnItemClickListener{
  
      ArrayList&lt;Detail&gt; items;
      ListAdapter adapter;
      private onClickListener OCL;
  
      interface onClickListener{
          public void onItemClick(int id);
      }
  
      public List(ArrayList&lt;Detail&gt; items) {
          this.items = items;
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
  
          View root = inflater.inflate(R.layout.list_layout, container, false);
          return root;
      }
  
      @Override
      public void onActivityCreated(Bundle savedInstanceState) {
          super.onActivityCreated(savedInstanceState);
  
          if(items != null){
              adapter = new ListAdapter(getActivity(), items);
              setListAdapter(adapter);
              getListView().setOnItemClickListener(this);
          }
  
      }
  
      @Override
      public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position,
              long id) {
  
          if(OCL != null){
              OCL.onItemClick(position);
          }       
      }
  }
  </code></pre>
  <p><strong>list_layout.xml</strong></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      android:id=&quot;@+id/LinearLayout1&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      android:orientation=&quot;vertical&quot; &gt;
      &lt;ListView
          android:id=&quot;@+id/android:list&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;match_parent&quot; &gt;
      &lt;/ListView&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  <p><strong>list_row</strong></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      android:orientation=&quot;horizontal&quot;
      android:padding=&quot;10dp&quot; &gt;
      &lt;TextView
          android:id=&quot;@+id/itemTitle&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_weight=&quot;0.96&quot;
          android:text=&quot;Medium Text&quot;
          android:textAppearance=&quot;?android:attr/textAppearanceMedium&quot; /&gt;
      &lt;CheckBox
          android:id=&quot;@+id/itemDone&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:text=&quot;Done&quot; /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  <p><strong>activity_main.xml</strong></p>
  <pre><code>&lt;RelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:id=&quot;@+id/container&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      android:paddingBottom=&quot;@dimen/activity_vertical_margin&quot;
      android:paddingLeft=&quot;@dimen/activity_horizontal_margin&quot;
      android:paddingRight=&quot;@dimen/activity_horizontal_margin&quot;
      android:paddingTop=&quot;@dimen/activity_vertical_margin&quot;
      tools:context=&quot;com.example.com.hermods.lab2_2.Main&quot; &gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  <p><strong>Log</strong></p>
  <pre><code>02-19 09:10:47.421: E/AndroidRuntime(12745): Process: com.example.com.hermods.lab2_2, PID: 12745
  02-19 09:10:47.421: E/AndroidRuntime(12745): java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getImportantForAccessibility()' on a null object reference
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.widget.AbsListView.obtainView(AbsListView.java:2360)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.widget.ListView.makeAndAddView(ListView.java:1864)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.widget.ListView.fillDown(ListView.java:698)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.widget.ListView.fillFromTop(ListView.java:759)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.widget.ListView.layoutChildren(ListView.java:1673)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.widget.AbsListView.onLayout(AbsListView.java:2148)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.view.View.layout(View.java:15596)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.view.ViewGroup.layout(ViewGroup.java:4966)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.view.View.layout(View.java:15596)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.view.ViewGroup.layout(ViewGroup.java:4966)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.view.View.layout(View.java:15596)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.view.ViewGroup.layout(ViewGroup.java:4966)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.view.View.layout(View.java:15596)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.view.ViewGroup.layout(ViewGroup.java:4966)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.view.View.layout(View.java:15596)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.view.ViewGroup.layout(ViewGroup.java:4966)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.view.View.layout(View.java:15596)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.view.ViewGroup.layout(ViewGroup.java:4966)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2072)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1829)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1054)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5779)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.view.Choreographer.doCallbacks(Choreographer.java:580)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.view.Choreographer.doFrame(Choreographer.java:550)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.os.Handler.handleCallback(Handler.java:739)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.os.Handler.dispatchMessage(Handler.java:95)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.os.Looper.loop(Looper.java:135)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at android.app.ActivityThread.main(ActivityThread.java:5221)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at java.lang.reflect.Method.invoke(Native Method)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at java.lang.reflect.Method.invoke(Method.java:372)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
  02-19 09:10:47.421: E/AndroidRuntime(12745):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
  </code></pre>