title: Exception: Attempt to invoke virtual method 'android.view.LayoutInflater android.app.Activity.getLayoutInflater()' on a null object reference
body: <p>I get this exception <code>Attempt to invoke virtual method 'android.view.LayoutInflater android.app.Activity.getLayoutInflater()' on a null object reference</code> but I am able to find the reason.</p>
  
  <p>In the mainactivity I create a ListView element, the structure is:</p>
  
  <pre><code>&lt;ListView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/list"
  /&gt;
  </code></pre>
  
  <p>And I create a custom Adapter class for the listview,</p>
  
  <pre><code>class ListItem
  {
      public String shortDescription;
      public String type;
      public String time;
      public int imageId;
  
      public ListItem(String sd, String type, String time, Integer imageId)
      {
          this.shortDescription = sd;
          this.type = type;
          this.time = time;
          this.imageId = imageId;
      }
  }
  
  
  public class CustomList extends ArrayAdapter&lt;Object&gt;{
  
      private Activity context;
      private ListItem listItem[];
  
      public CustomList(Activity context, ListItem li[]){
          super(context, R.layout.rowlayout, li);
          this.listItem = li;
      }
  
      @Override
      public View getView(int position, View view, ViewGroup parent)
      {
          LayoutInflater inflater = context.getLayoutInflater();
          View rowView = inflater.inflate(R.layout.rowlayout, null, true);
          TextView sd = (TextView)rowView.findViewById(R.id.sd);
          TextView type = (TextView)rowView.findViewById(R.id.type);
          TextView days = (TextView)rowView.findViewById(R.id.days);
          ImageView icon = (ImageView)rowView.findViewById(R.id.icon);
  
          sd.setText(listItem[position].shortDescription);
          type.setText(listItem[position].type);
          days.setText(listItem[position].time);
          icon.setImageResource(listItem[position].imageId);
          return rowView;
      }
  </code></pre>
  
  <p>And I call this in my MainActivity class,</p>
  
  <pre><code>public class MainActivity extends ActionBarActivity {
  
      ListView listView;
      ListItem listItem[] = new ListItem[2];
      Integer[] imageId = {R.drawable.ic_launcher};
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          listItem[0] = new ListItem("test", "test", "test", imageId[0]);
          listItem[1] = new ListItem("test1", "test1", "test1", imageId[0]);
  
          CustomList adapter = new CustomList(MainActivity.this, listItem);
          listView = (ListView)findViewById(R.id.list);
          listView.setAdapter(adapter);
      }
  }
  </code></pre>
  
  <p>I get the exception in the custom Adapter class , at <strong>LayoutInflater inflater = context.getLayoutInflater();</strong>. But the variable <strong>context</strong> is initialized in the constructor call itself. Why does it throw an Exception? </p>