title: ListView setAdapter on null object reference
body: <p>I'v been transfering code from activity to fragment, I have simillar app that works perfectly and i checked each sentance, looks like everything matches but faced this problem,.</p>
  
  <p>Actual error:</p>
  
  <blockquote>
  <pre><code>                                                                     Process: com.example.android.miwok, PID: 7432
                                                                       java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.miwok/com.example.android.miwok.Numbers_activity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
                                                                           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
                                                                           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
                                                                           at android.app.ActivityThread.-wrap14(ActivityThread.java)
                                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
                                                                           at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                           at android.os.Looper.loop(Looper.java:154)
                                                                           at android.app.ActivityThread.main(ActivityThread.java:6682)
                                                                           at java.lang.reflect.Method.invoke(Native Method)
                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
                                                                        Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
                                                                           at com.example.android.miwok.numeriuFragmentai.onCreateView(numeriuFragmentai.java:81)
                                                                           at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
                                                                           at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
                                                                           at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
                                                                           at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742)
                                                                           at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
                                                                           at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:339)
                                                                           at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:602)
                                                                           at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1256)
                                                                           at android.app.Activity.performStart(Activity.java:6959)
                                                                           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2890)
                                                                           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988) 
                                                                           at android.app.ActivityThread.-wrap14(ActivityThread.java) 
                                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631) 
                                                                           at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                           at android.os.Looper.loop(Looper.java:154) 
                                                                           at android.app.ActivityThread.main(ActivityThread.java:6682) 
                                                                           at java.lang.reflect.Method.invoke(Native Method) 
                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) 
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) 
  </code></pre>
  </blockquote>
  
  <p>checked with other simillar code everything matches but i'm sure i missed something.</p>
  
  <p>numeriuFragmentai.java</p>
  
  <pre><code>package com.example.android.miwok;
  
  
  import android.content.Context;
  import android.media.AudioManager;
  import android.media.MediaPlayer;
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.AdapterView;
  import android.widget.ListView;
  import com.example.android.miwok.word;
  import com.example.android.miwok.Adaptoreditor;
  import android.view.LayoutInflater;
  import java.util.ArrayList;
  
  import static com.example.android.miwok.R.id.container;
  
  
  public class numeriuFragmentai extends Fragment {
  
  private MediaPlayer mMediaPlayer;
  
  private AudioManager mAudio;
  
  private AudioManager.OnAudioFocusChangeListener focuslistener = new AudioManager.OnAudioFocusChangeListener() {
      @Override
      public void onAudioFocusChange(int focusChange) {
          if (focusChange==AudioManager.AUDIOFOCUS_LOSS_TRANSIENT || focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK)
          {
              mMediaPlayer.pause();
              mMediaPlayer.seekTo(0);
          }
          else if (focusChange==AudioManager.AUDIOFOCUS_GAIN)
          {
              mMediaPlayer.start();
          }
          else if (focusChange==AudioManager.AUDIOFOCUS_LOSS)
          {
              releaseMediaPlayer();
          }
      }
  };
  private MediaPlayer.OnCompletionListener completed = new MediaPlayer.OnCompletionListener() {
      @Override
      public void onCompletion(MediaPlayer mediaPlayer) {
          releaseMediaPlayer();
      }
  };
  public numeriuFragmentai() {
  
  }
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
  
      View rootView = inflater.inflate(R.layout.list_item, container, false);
  
      mAudio=(AudioManager)getActivity().getSystemService(Context.AUDIO_SERVICE);
  
      final ArrayList&lt;word&gt; numbers = new ArrayList&lt;word&gt;();
      numbers.add(new word(R.string.number_one, R.string.miwok_number_one,R.drawable.yplay, R.raw.number_one, R.drawable.number_one));
      numbers.add(new word(R.string.number_two, R.string.miwok_number_two,R.drawable.yplay, R.raw.number_two, R.drawable.number_two));
      numbers.add(new word(R.string.number_three, R.string.miwok_number_three,R.drawable.yplay, R.raw.number_three, R.drawable.number_three));
      numbers.add(new word(R.string.number_four, R.string.miwok_number_four,R.drawable.yplay, R.raw.number_four, R.drawable.number_four));
      numbers.add(new word(R.string.number_five, R.string.miwok_number_five, R.drawable.yplay, R.raw.number_five, R.drawable.number_five));
      numbers.add(new word(R.string.number_six, R.string.miwok_number_six,R.drawable.yplay, R.raw.number_six, R.drawable.number_six));
      numbers.add(new word(R.string.number_seven, R.string.miwok_number_seven,R.drawable.yplay, R.raw.number_seven, R.drawable.number_seven));
      numbers.add(new word(R.string.number_eight, R.string.miwok_number_eight,R.drawable.yplay, R.raw.number_eight, R.drawable.number_eight));
      numbers.add(new word(R.string.number_nine, R.string.miwok_number_nine,R.drawable.yplay, R.raw.number_nine, R.drawable.number_nine));
      numbers.add(new word(R.string.number_ten, R.string.miwok_number_ten,R.drawable.yplay, R.raw.number_ten, R.drawable.number_ten));
  
      Adaptoreditor adapteris = new Adaptoreditor(getActivity(), numbers, R.color.numeriai);
  
      Adaptoreditor adapter = new Adaptoreditor(getActivity(), numbers, R.color.spalvos);
  
      ListView listView = (ListView) rootView.findViewById(R.id.list);
  
      listView.setAdapter(adapter);
  
      listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; adapterView, View view, int position, long l) {
  
              releaseMediaPlayer();
  
              word words = numbers.get(position);
  
              int result = mAudio.requestAudioFocus(focuslistener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
  
              if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
  
                  mMediaPlayer = MediaPlayer.create(getActivity(), words.getSound());
                  mMediaPlayer.start();
                  mMediaPlayer.setOnCompletionListener(completed);
              }
          }
      });
  
      return rootView;
  }
  @Override
  public void onStop() {
      super.onStop();
      releaseMediaPlayer();
  }
  private void releaseMediaPlayer()
  {
      if (mMediaPlayer!=null)
      {
          mMediaPlayer.release();
          mMediaPlayer=null;
          mAudio.abandonAudioFocus(focuslistener);
      }
  }
  }
  </code></pre>
  
  <p>NumbersActivity.java</p>
  
  <pre><code>package com.example.android.miwok;
  
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  
  public class Numbers_activity extends AppCompatActivity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_category);
      getSupportFragmentManager().beginTransaction()
              .replace(R.id.container, new numeriuFragmentai())
              .commit();
  }
  }
  </code></pre>
  
  <p>Adaptoreditor.java</p>
  
  <pre><code>package com.example.android.miwok;
  
  import android.content.Context;
  import android.support.v4.content.ContextCompat;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ArrayAdapter;
  import android.widget.ImageView;
  import android.widget.TextView;
  import com.example.android.miwok.word;
  
  import java.util.ArrayList;
  
  public class Adaptoreditor extends ArrayAdapter&lt;word&gt; {
  
      private int mcolorid;
  
      public Adaptoreditor(Context context, ArrayList&lt;word&gt; word, int colorid) {
  
          super(context, 0, word);
          mcolorid=colorid;
      }
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          View listItemView = convertView;
          if(listItemView == null) {
              listItemView = LayoutInflater.from(getContext()).inflate(R.layout.list_item, parent, false);
          }
          word vertimas = getItem(position);
  
          TextView nameTextView = (TextView) listItemView.findViewById(R.id.first);
          nameTextView.setText(vertimas.getMiwok());
  
          TextView numberTextView = (TextView) listItemView.findViewById(R.id.second);
  
          numberTextView.setText(vertimas.getTranslated());
  
          ImageView img = (ImageView) listItemView.findViewById(R.id.img);
  
          if (vertimas.yrft()) {
  
              img.setImageResource(vertimas.getImgR());
              img.setVisibility(View.VISIBLE);
          } else {
  
              img.setVisibility(View.GONE);
          }
  
          ImageView pic = (ImageView)listItemView.findViewById(R.id.player);
          pic.setImageResource(vertimas.getPlayImg());
  
          View vieta = listItemView.findViewById(R.id.linearas);
          int color = ContextCompat.getColor(getContext(), mcolorid);
          vieta.setBackgroundColor(color);
  
          return listItemView;
      }
  }
  </code></pre>
  
  <p>word.java</p>
  
  <pre><code>package com.example.android.miwok;
  
  
  public class word {
  
     private int mtranslated;
  
     private  int mmiwok;
  
      private int mimgid=NER_FOTO;
  
      private int mpImg;
  
      private int mSound;
  
      public final static int NER_FOTO = -1;
  
      public word (int translated, int miwok, int pimg,int sound)
      {
          mtranslated = translated;
          mmiwok=miwok;
          mpImg=pimg;
          mSound=sound;
      }
      public word (int translated, int miwok,int pimg, int sound,int imgid)
      {
          mtranslated = translated;
          mmiwok=miwok;
          mimgid=imgid;
          mpImg=pimg;
          mSound=sound;
      }
      public int getMiwok()
      {
          return mmiwok;
      }
      public int getTranslated()
      {
          return mtranslated;
      }
      public int getSound(){return  mSound;}
      public int getImgR ()
      {
          return mimgid;
      }
      public int getPlayImg ()
      {
          return mpImg;
      }
      public boolean yrft ()
      {
          return mimgid !=NER_FOTO;
      }
  }
  </code></pre>
  
  <p>activity_category.XML</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/container"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      /&gt;
  </code></pre>
  
  <p>List_item.XML</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="88dp"
      android:id="@+id/linearas"
      android:background="?android:attr/selectableItemBackground"&gt;
  
      &lt;ImageView
      android:layout_width="32dp"
      android:layout_height="40dp"
      android:src="@mipmap/ic_launcher"
      android:layout_centerInParent="true"
      android:layout_alignParentRight="true"
      android:layout_marginRight="8dp"
      android:id="@+id/player"/&gt;
  &lt;LinearLayout
      android:orientation="horizontal"
      android:layout_width="wrap_content"
      android:layout_height="88dp"
      android:layout_alignParentTop="true"
      android:layout_alignParentLeft="true"
      android:layout_alignParentStart="true"&gt;
      &lt;ImageView
          android:layout_width="88dp"
          android:layout_height="88dp"
          tools:src="@mipmap/ic_launcher"
          android:id="@+id/img"
          /&gt;
  
  &lt;LinearLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      android:gravity="center_vertical"
      android:paddingLeft="16dp"&gt;
  
          &lt;TextView
              android:id="@+id/first"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:textStyle="bold"
              tools:text="Pirmas" /&gt;
  
          &lt;TextView
              android:id="@+id/second"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              tools:text="Antras" /&gt;
  &lt;/LinearLayout&gt;
  &lt;/LinearLayout&gt;
  &lt;/RelativeLayout
  </code></pre>
  
  <p>Wordlist.XML</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ListView xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/list"
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:drawSelectorOnTop="true"/&gt;
  </code></pre>
  
  <p>Link to whole app 
  <a href="https://drive.google.com/file/d/0BzUjPHoTnBaISmx2Q1BkMm52bFU/view?usp=sharing" rel="nofollow noreferrer">App</a></p>