title: NullPointerException while setAdapter for listView
body: <p>I am getting stuck in this line for 5 days. Would you like to help me why it say Null Pointer Exception when I setAdapter for it.</p>
  
  <p>This is ListFileController</p>
  
  <pre><code>public class ListFileController extends ArrayAdapter&lt;Files&gt; {
  private Context context;
  private int layoutId;
  ArrayList&lt;Files&gt; array;
  
  public ListFileController(Context context, int layoutId, ArrayList&lt;Files&gt; array) {
      super(context, layoutId, array);
  
      this.context = context;
      this.layoutId = layoutId;
      this.array = array;
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
      LayoutInflater inflater;
      View rowView = convertView;
      ViewHolder holder = null;
      if (rowView == null){
          holder = new ViewHolder();
  
          inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
  
          rowView = inflater.inflate(R.layout.list_file_layout, parent, false);
          holder.icon = (ImageView) rowView.findViewById(R.id.icon);
          holder.fileName = (TextView) rowView.findViewById(R.id.fileName);
          holder.size = (TextView) rowView.findViewById(R.id.fileSize);
  
          rowView.setTag(holder);
      }
      else{
          holder =  (ViewHolder) rowView.getTag();
      }
  
      Files i = array.get(position);
      if (array.get(position).isFolder() == 1){
          holder.icon.setImageResource(R.drawable.folder);
      }
      else if (array.get(position).isFolder() == 0){
          if (array.get(position).getFileType().contains("image") || array.get(position).getFileType().contains("picture"))
              holder.icon.setImageResource(R.drawable.image);
          else if (array.get(position).getFileType().contains("sound")|| array.get(position).getFileType().contains("music"))
              holder.icon.setImageResource(R.drawable.audio);
          else if (array.get(position).getFileType().contains("video")|| array.get(position).getFileType().contains("film"))
              holder.icon.setImageResource(R.drawable.video);
          else
              holder.icon.setImageResource(R.drawable.file);
      }
      else
          holder.icon.setImageResource(R.drawable.back);
  
      holder.fileName.setText(array.get(position).getFileName());
      holder.size.setText(array.get(position).getFileName());
  
      return rowView;
  }
  
  public static class ViewHolder{
      ImageView icon;
      TextView fileName;
      TextView size;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>This is my MainActivity</p>
  
  <pre><code>public class MainActivity extends Activity implements View.OnClickListener {
  
  private DropboxAPI&lt;AndroidAuthSession&gt; dropbox;
  final static private String ROOT = "/";
  private final static String APP_NAME = "dropbox_prefs";
  final static private String APP_KEY = "x7bv6zets19iqt4";
  final static private String APP_SECRET = "i95y5a09v0wlopu";
  private static final int REQUEST_PATH = 1;
  private ArrayAdapter&lt;Files&gt; controller = null;
  
  private AlertDialog.Builder alter;
  private AlertDialog.Builder inputbuilder;
  
  private String deviceFilePath;
  private String deviceFilename;
  
  public ArrayList&lt;Files&gt; listOfFiles = new ArrayList&lt;Files&gt;();
  public ArrayList&lt;Files&gt; fileFromDropbox = new ArrayList&lt;Files&gt;();
  public ArrayList&lt;String&gt; listOfFolder = new ArrayList&lt;String&gt;();
  
  private Files selected;
  private String currentPath = ROOT;
  private String previousPath = "";
  
  public boolean isLoggedIn;
  public Button logInBut;
  public Button uploadBut;
  public Button listFilesBut;
  ViewStub listView;
  private ListView list;
  
  
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      isLoggedIn = false;
  
      // Creating button on the screen
      logInBut = (Button) findViewById(R.id.logInBut);
      logInBut.setOnClickListener(this);
  
      uploadBut = (Button) findViewById(R.id.uploadBut);
      uploadBut.setOnClickListener(this);
  
  
      listView = (ViewStub) findViewById(R.id.list_stub);
      listView.inflate();
      list = (ListView) findViewById(R.id.list_stub);
  
  
      // Create an array to store item &gt;&gt; Init 1 item to make array not null
      fileFromDropbox.add(new Files("1st", "test", 0));
      listOfFiles.add(new Files ("1st", "test", 0));
  
      controller = new ListFileController(MainActivity.this, android.R.layout.simple_list_item_1,
              listOfFiles);
      list.setAdapter(controller);
  
      list.setOnItemLongClickListener(new OnItemLongClickListener() {
  
          @Override
          public boolean onItemLongClick(AdapterView&lt;?&gt; parent, View view,
                                         int position, long id) {
              // TODO Auto-generated method stub
              selected = controller.getItem(position);
              if (selected.isFolder() == 1) {
                  folderOptionDialog();
              }
              return true;
          }
  
      });
  
      list.setOnItemClickListener(new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                                  int position, long id) {
              // TODO Auto-generated method stub
              selected = controller.getItem(position);
              if (selected.isFolder() == 1) {
                  currentPath = selected.getPath();
                  updateList(selected.getPath());
  
              } else if (selected.isFolder() == 2) {
                  updateList(selected.getParentPath());
  
              } else {
                  currentPath = selected.getParentPath();
                  fileOptions();
  
              }
              controller.notifyDataSetChanged();
          }
      });
      // Authentication dropbox API account
      checkLogIn(false);
      AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);
      AndroidAuthSession session = new AndroidAuthSession(appKeys);
      dropbox = new DropboxAPI&lt;AndroidAuthSession&gt;(session);
      dropbox.getSession().startOAuth2Authentication(MainActivity.this);
  
  
      ConnectivityManager connectivityChecker = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
  
      //For 3G check
      boolean is3G = connectivityChecker.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
              .isConnectedOrConnecting();
      //For WiFi Check
      boolean isWifi = connectivityChecker.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
              .isConnectedOrConnecting();
  
      if (!is3G &amp;&amp; !isWifi)
          Toast.makeText(MainActivity.this, "Please connect to the internet", Toast.LENGTH_LONG).show();
      if (!isWifi)
          Toast.makeText(MainActivity.this, "3G service is currently not available, please connect via WIFI", Toast.LENGTH_LONG).show();
  
  
  }
  
  
  private void setAdapter() {
  
          controller = new ListFileController(this,android.R.layout.simple_list_item_1, listOfFiles);
          list.setAdapter(controller);
          list.setOnItemClickListener(new OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                                      int position, long id) {
                  // TODO Auto-generated method stub
                  selected = controller.getItem(position);
  
                  if (selected.isFolder() == 1) {
                      currentPath = selected.getPath();
                      updateList(selected.getPath());
  
                  } else if (selected.isFolder() == 2) {
                      updateList(selected.getParentPath());
  
                  } else {
                      currentPath = selected.getParentPath();
                      fileOptions();
  
                  }
                  controller.notifyDataSetChanged();
              }
          });
  
          list.setOnItemLongClickListener(new OnItemLongClickListener(){
  
              @Override
              public boolean onItemLongClick(AdapterView&lt;?&gt; parent, View view,
                                             int position, long id) {
                  // TODO Auto-generated method stub
                  selected = controller.getItem(position);
                  if (selected.isFolder() == 1) {
                      folderOptionDialog();
                  }
                  return true;
              }
  
          });
  }
  </code></pre>
  
  <p>This is my XML file which contain list.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;merge xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent" &gt;
  
  &lt;LinearLayout
  android:id="@+id/LinearLayout1"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical" &gt;
  
  &lt;Button
      android:id="@+id/logInBut"
      android:layout_marginLeft = "15dp"
      android:layout_marginRight="15dp"
      android:layout_width="373dp"
      android:layout_height="243dp"
      android:textColor="#43b8e3"
      android:text="LOG IN"
      android:textSize="100dp"
      android:layout_gravity="center_horizontal"
      android:enabled="false" /&gt;
  
  &lt;Button
      android:id="@+id/uploadBut"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:text="UPLOAD"
      android:textColor="#43b8e3"
      android:textSize="80dp"
      android:layout_weight="0.01"
      android:layout_gravity="center_horizontal" /&gt;
  
  
  &lt;ViewStub
      android:id="@+id/list_stub"
      android:inflatedId="@+id/showlayout"
      android:layout="@layout/activity_list_file"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_marginTop="10dp"/&gt;
  
  
  &lt;/LinearLayout&gt;
  &lt;/merge&gt;
  </code></pre>
  
  <p>And the last one is the layout</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="match_parent"
  android:layout_height="match_parent"&gt;
  
  &lt;ListView android:id="@android:id/list"
      android:layout_width="match_parent"
      android:layout_height="wrap_content" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>