title: Cannot resolve NullPointerException even after checking layout references
body: <p>I understand that the cause might be I am not referencing the right Layout which has the Id's. However, I am certain they the Id's are there in the corresponding layout. I am getting this error as I start to include alert dialogs, is this being caused by the inflater? Appreciate the help here. </p>
  
  <p>A brief overview of what im trying to do: my main activity is a viewpager which has 3 fragments. I am mainly working on the 1st fragment, fragment main. On launch, the app will ask for a new player name and then transfer that data to a player class. My button simply opens up a dialog which will show the details related to the created "newplayer". Hope this helps.</p>
  
  <pre><code>package fantasy.myapplication;
  
  import android.app.Dialog;
  import android.support.design.widget.TabLayout;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentPagerAdapter;
  import android.support.v4.view.ViewPager;
  import android.support.v7.app.AlertDialog;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.support.v7.widget.Toolbar;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.WindowManager;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.TextView;
  
  import cn.pedant.SweetAlert.SweetAlertDialog;
  import fantasy.myapplication.Fragments.fragment_army;
  import fantasy.myapplication.Fragments.fragment_main;
  import fantasy.myapplication.Fragments.fragment_treasures;
  import fantasy.myapplication.player.player;
  
  public class MainActivity extends AppCompatActivity {
  
  private SectionsPagerAdapter mSectionsPagerAdapter;
  private ViewPager mViewPager;
  private TabLayout tabLayout;
  public player thisplayer;
  public String playerID;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
      setContentView(R.layout.activity_main);
  
      final Button btn_playerinfo = (Button) findViewById(R.id.btnplayerid);
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
      getSupportActionBar().setDisplayShowTitleEnabled(false);
      toolbar.setTitle("");
      toolbar.setSubtitle("");
  
      mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
      mViewPager = (ViewPager) findViewById(R.id.container);
      mViewPager.setAdapter(mSectionsPagerAdapter);
  
      TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
      tabLayout.setupWithViewPager(mViewPager);
  
      mViewPager.setCurrentItem(2);
  
      //Setup Player
      View popup_newplayer = (LayoutInflater.from(MainActivity.this)).inflate(R.layout.popup_newplayer,null);
      AlertDialog.Builder alert_newplayer = new AlertDialog.Builder(MainActivity.this);
      alert_newplayer.setView(popup_newplayer);
  
      final EditText newplayerid = (EditText) popup_newplayer.findViewById(R.id.tb_newplayer);
      Button btn_newplayer_create = (Button) popup_newplayer.findViewById(R.id.btn_newplayer_ok);
      Button btn_newplayer_cancel = (Button) popup_newplayer.findViewById(R.id.btn_newplayer_cancel);
  
      final Dialog dialog_newplayer = alert_newplayer.create();
      dialog_newplayer.show();
  
      btn_newplayer_create.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              dialog_newplayer.dismiss();
              playerID = newplayerid.getText().toString();
              thisplayer = new player(playerID);
              btn_playerinfo.setText(newplayerid.getText());
              new SweetAlertDialog(MainActivity.this, SweetAlertDialog.SUCCESS_TYPE)
                      .setTitleText("Success!")
                      .setContentText("New player "+playerID+" created!")
                      .show();
  
          }
      });
  
      btn_newplayer_cancel.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              dialog_newplayer.dismiss();
          }
      });
  
      btn_playerinfo.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              //Display Player Info
  
              View popup_playerinfo = (LayoutInflater.from(MainActivity.this)).inflate(R.layout.popup_playerinfo,null);
              AlertDialog.Builder alert_playerinfo = new AlertDialog.Builder(MainActivity.this);
              alert_playerinfo.setView(popup_playerinfo);
  
              TextView playerinfo_id = (TextView) popup_playerinfo.findViewById(R.id.info_playerid);
              playerinfo_id.setText(newplayerid.getText());
  
              final Dialog dialog_playerinfo = alert_playerinfo.create();
              dialog_playerinfo.show();
          }
      });
  
  }
  
  public class SectionsPagerAdapter extends FragmentPagerAdapter {
  
      public SectionsPagerAdapter(FragmentManager fm) { super(fm);}
  
      @Override
      public Fragment getItem(int position) {
          //return the current tabs
          switch (position) {
              case 0:
                  return new fragment_army();
              case 1:
                  return new fragment_treasures();
              case 2:
                  return new fragment_main();
              default:
                  return null;
          }
      }
  
      @Override
      public CharSequence getPageTitle(int position) {
          switch (position) {
              case 0:
                  return "Army";
              case 1:
                  return "Treasures";
              case 2:
                  return "Main";
          }
          return null;
      }
  
      @Override
      public int getCount() {return 3;}
  }
  </code></pre>
  
  <p>This is my main Fragment XML code:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="@drawable/main_bg"&gt;
  
  
  &lt;TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Main page"
      android:id="@+id/textView"
      android:layout_centerVertical="true"
      android:layout_centerHorizontal="true" /&gt;
  
  &lt;Button
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Player ID"
      android:id="@+id/btnplayerid"
      android:layout_alignParentTop="true"
      android:layout_alignParentLeft="true"
      android:layout_alignParentStart="true"
      android:layout_marginTop="26dp"
      android:textSize="10dp" /&gt;
  
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>This is the activity_main 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:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context="fantasy.myapplication.MainActivity"
  android:id="@+id/main_activity"&gt;
  
  &lt;android.support.v7.widget.Toolbar
      android:layout_width="match_parent"
      android:layout_height="?attr/actionBarSize"
      android:id="@+id/toolbar"
      android:background="?attr/colorPrimary"
      android:layout_alignParentBottom="true"&gt;
  &lt;/android.support.v7.widget.Toolbar&gt;
  
  &lt;android.support.design.widget.TabLayout
      android:id="@+id/tabs"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      app:tabIndicatorColor="#ffffff"
      app:tabGravity="fill"/&gt;
  
  &lt;android.support.v4.view.ViewPager
      android:id="@+id/container"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      app:layout_behavior="@string/appbar_scrolling_view_behavior"
      android:layout_above="@id/tabs"/&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>My Fragment Class</p>
  
  <pre><code>package fantasy.myapplication.Fragments;
  
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  import fantasy.myapplication.R;
  
  public class fragment_main extends Fragment {
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.fragment_main, container, false);
      return rootView;
  }
  
  }
  </code></pre>