title: When setting an Adapter it Gives a Null Pointer Exception in fragment
body: <p>I am a new android learner. I ran into this null pointer exception at <code>setAdapter()</code> for lListView<code>. Both the</code>ListView` and the Adapter are NOT null.
  I have attached my logcat and fragament, adapter code. I have searched the Internet, and I thought it might have something to do with Fragment. </p>
  
  <p><strong>News_Title_fragment:</strong></p>
  
  <pre><code>package com.example.fragmentbestpractice;
  import java.util.ArrayList;
  import java.util.List;
  import android.app.Activity;
  import android.app.Fragment;
  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;
  import android.widget.ListView;
  
  public class NewsTitleFragment extends Fragment implements OnItemClickListener {
  
      private ListView newsTitleListView;
  
      private List&lt;News&gt; newsList;
  
      private NewsAdapter adapter;
  
      private boolean isTwoPane;
  
      @Override
      public void onAttach(Activity activity) {
          super.onAttach(activity);
          newsList = getNews();
          adapter = new NewsAdapter(activity, R.layout.news_item, newsList);
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.news_title_frag, container, false);
          newsTitleListView = (ListView) view.findViewById(R.id.news_title_list_view);
          newsTitleListView.setAdapter(adapter);
          newsTitleListView.setOnItemClickListener(this);
          return view;
      }
  
      @Override
      public void onActivityCreated(Bundle savedInstanceState) {
          super.onActivityCreated(savedInstanceState);
          if (getActivity().findViewById(R.id.news_content_layout) != null) {
              isTwoPane = true;
          } else {
              isTwoPane = false;
          }
      }
  
      @Override
      public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position,
              long id) {
          News news = newsList.get(position);
          if (isTwoPane) {
              NewsContentFragment newsContentFragment = (NewsContentFragment) getFragmentManager()
                      .findFragmentById(R.id.news_content_fragment);
              newsContentFragment.refresh(news.getTitle(), news.getContent());
          } else {
              NewsContentActivity.actionStart(getActivity(), news.getTitle(),
                      news.getContent());
          }
      }
  
      private List&lt;News&gt; getNews() {
          List&lt;News&gt; newsList = new ArrayList&lt;News&gt;();
          News news1 = new News();
          news1.setTitle("Succeed in College as a Learning Disabled Student");
          news1.setContent("College freshmen will soon learn to live with a roommate, adjust to a new social scene and survive less-than-stellar dining hall food. Students with learning disabilities will face these transitions while also grappling with a few more hurdles.");
          newsList.add(news1);
          News news2 = new News();
          news2.setTitle("Google Android exec poached by China's Xiaomi");
          news2.setContent("China's Xiaomi has poached a key Google executive involved in the tech giant's Android phones, in a move seen as a coup for the rapidly growing Chinese smartphone maker.");
          newsList.add(news2);
          return newsList;
      }
  
  }
  </code></pre>
  
  <p>NewsAdapter:</p>
  
  <pre><code>package com.example.fragmentbestpractice;
  
  import java.util.List;
  
  import android.content.Context;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ArrayAdapter;
  import android.widget.TextView;
  
  public class NewsAdapter extends ArrayAdapter&lt;News&gt; {
  
      private int resourceId;
  
      public NewsAdapter(Context context, int textViewResourceId, List&lt;News&gt; objects) {
          super(context, textViewResourceId, objects);
          resourceId = textViewResourceId;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          News news = getItem(position);
          View view;
          if (convertView == null) {
              view = LayoutInflater.from(getContext()).inflate(resourceId, null);
          } else {
              view = convertView;
          }
          TextView newsTitleText = (TextView) view.findViewById(R.id.news_title);
          newsTitleText.setText(news.getTitle());
          return view;
      }
  
  }
  </code></pre>
  
  <p>Logcat:</p>
  
  <pre><code> 06-30 21:45:03.099: E/AndroidRuntime(31769): FATAL EXCEPTION: main
  06-30 21:45:03.099: E/AndroidRuntime(31769): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.youdianin.fragamentbestpratice/com.youdianin.fragamentbestpratice.MainActivity}: android.view.InflateException: Binary XML file line #5: Error inflating class fragment
  06-30 21:45:03.099: E/AndroidRuntime(31769):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2092)
  06-30 21:45:03.099: E/AndroidRuntime(31769):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2117)
  06-30 21:45:03.099: E/AndroidRuntime(31769):    at android.app.ActivityThread.access$600(ActivityThread.java:140)
  06-30 21:45:03.099: E/AndroidRuntime(31769):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1213)
  06-30 21:45:03.099: E/AndroidRuntime(31769):    at android.os.Handler.dispatchMessage(Handler.java:99)
  06-30 21:45:03.099: E/AndroidRuntime(31769):    at android.os.Looper.loop(Looper.java:137)
  06-30 21:45:03.099: E/AndroidRuntime(31769):    at android.app.ActivityThread.main(ActivityThread.java:4914)
  06-30 21:45:03.099: E/AndroidRuntime(31769):    at java.lang.reflect.Method.invokeNative(Native Method)
  06-30 21:45:03.099: E/AndroidRuntime(31769):    at java.lang.reflect.Method.invoke(Method.java:511)
  06-30 21:45:03.099: E/AndroidRuntime(31769):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:808)
  06-30 21:45:03.099: E/AndroidRuntime(31769):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:575)
  06-30 21:45:03.099: E/AndroidRuntime(31769):    at dalvik.system.NativeStart.main(Native Method)
  06-30 21:45:03.099: E/AndroidRuntime(31769): Caused by: android.view.InflateException: Binary XML file line #5: Error inflating class fragment
  06-30 21:45:03.099: E/AndroidRuntime(31769):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:774)
  06-30 21:45:03.099: E/AndroidRuntime(31769):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:816)
  06-30 21:45:03.099: E/AndroidRuntime(31769):    at android.view.LayoutInflater.inflate(LayoutInflater.java:559)
  06-30 21:45:03.099: E/AndroidRuntime(31769):    at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
  06-30 21:45:03.099: E/AndroidRuntime(31769):    at android.view.LayoutInflater.inflate(LayoutInflater.java:417)
  06-30 21:45:03.099: E/AndroidRuntime(31769):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:334)
  06-30 21:45:03.099: E/AndroidRuntime(31769):    at android.app.Activity.setContentView(Activity.java:1944)
  06-30 21:45:03.099: E/AndroidRuntime(31769):    at com.youdianin.fragamentbestpratice.MainActivity.onCreate(MainActivity.java:14)
  06-30 21:45:03.099: E/AndroidRuntime(31769):    at android.app.Activity.performCreate(Activity.java:5086)
  06-30 21:45:03.099: E/AndroidRuntime(31769):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
  06-30 21:45:03.099: E/AndroidRuntime(31769):    at com.lbe.security.service.core.client.b.x.callActivityOnCreate(Unknown Source)
  06-30 21:45:03.099: E/AndroidRuntime(31769):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2056)
  06-30 21:45:03.099: E/AndroidRuntime(31769):    ... 11 more
  06-30 21:45:03.099: E/AndroidRuntime(31769): Caused by: java.lang.NullPointerException
  06-30 21:45:03.099: E/AndroidRuntime(31769):    at android.widget.ArrayAdapter.getCount(ArrayAdapter.java:330)
  06-30 21:45:03.099: E/AndroidRuntime(31769):    at android.widget.ListView.setAdapter(ListView.java:460)
  06-30 21:45:03.099: E/AndroidRuntime(31769):    at com.youdianin.fragamentbestpratice.NewsTitleFragment.onCreateView(NewsTitleFragment.java:51)
  06-30 21:45:03.099: E/AndroidRuntime(31769):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:807)
  06-30 21:45:03.099: E/AndroidRuntime(31769):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1013)
  06-30 21:45:03.099: E/AndroidRuntime(31769):    at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1112)
  06-30 21:45:03.099: E/AndroidRuntime(31769):    at android.app.Activity.onCreateView(Activity.java:4742)
  06-30 21:45:03.099: E/AndroidRuntime(31769):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)
  </code></pre>