title: Showing an AlertDialogFragment causes NullPointerException
body: <p>So I'm writing a game called rock, paper, scissors and I get a NullPointerException whenever I'm trying to prompt a user about difficulty. My intention is to launch a new activity passing the difficulty value via intent's putExtra method. This action is to be performed through a custom Dialog. Here is the log:</p>
  
  <pre><code>08-11 13:38:09.619    8725-8725/dserov.rockpaperscissors E/AndroidRuntime﹕ FATAL EXCEPTION: main
  Process: dserov.rockpaperscissors, PID: 8725
  java.lang.NullPointerException
          at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:394)
          at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
          at android.widget.AbsListView.obtainView(AbsListView.java:2255)
          at android.widget.ListView.measureHeightOfChildren(ListView.java:1263)
          at android.widget.ListView.onMeasure(ListView.java:1175)
          at android.view.View.measure(View.java:16497)
          at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
          at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
          at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
          at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
          at android.view.View.measure(View.java:16497)
          at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
          at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
          at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
          at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
          at android.view.View.measure(View.java:16497)
          at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
          at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
          at android.view.View.measure(View.java:16497)
          at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
          at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
          at android.view.View.measure(View.java:16497)
          at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
          at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
          at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
          at android.view.View.measure(View.java:16497)
          at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1912)
          at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1084)
          at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1291)
          at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996)
          at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600)
          at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
          at android.view.Choreographer.doCallbacks(Choreographer.java:574)
          at android.view.Choreographer.doFrame(Choreographer.java:544)
          at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
          at android.os.Handler.handleCallback(Handler.java:733)
          at android.os.Handler.dispatchMessage(Handler.java:95)
          at android.os.Looper.loop(Looper.java:136)
          at android.app.ActivityThread.main(ActivityThread.java:5001)
          at java.lang.reflect.Method.invokeNative(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:515)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
          at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Here is MainActivity:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
  @Bind(R.id.singleplayerButton) Button mSingleplayerButton;
  @Bind(R.id.multiplayerButton) Button mMultiplayerButton;
  @Bind(R.id.gameEmblem) ImageView mGameEmblem;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      ButterKnife.bind(this);
      View.OnClickListener listener = new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              switch (v.getId()) {
                  case (R.id.singleplayerButton) : {
                      AlertDialogFragment dialog = new AlertDialogFragment();
                      dialog.show(getFragmentManager(), getString(R.string.difficulty_dialog));
                      break;
                  }
  
                  case (R.id.multiplayerButton) : {
                      break;
                  }
  
              }
          }
      };
  
      mSingleplayerButton.setOnClickListener(listener);
      mMultiplayerButton.setOnClickListener(listener);
  }
  </code></pre>
  
  <p>Here is AlertDialogFragment:</p>
  
  <pre><code>public class AlertDialogFragment extends DialogFragment {
      @Override
      public Dialog onCreateDialog(Bundle savedInstanceState) {
          final Context context = getActivity();
          AlertDialog.Builder builder = new AlertDialog.Builder(context);
          builder.setTitle(R.string.difficulty_prompt)
              .setItems(R.array.difficulties, new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                      Intent intent = new Intent(context, PlayActivity.class);
                      switch (which) {
                          case 0 : {
                              intent.putExtra(context.getString(R.string.difficulty_label), 0);
                              break;
                          }
                          case 1 : {
                              intent.putExtra(context.getString(R.string.difficulty_label), 1);
                              break;
                          }
                      }
                      startActivity(intent);
                  }
              });
      AlertDialog dialog = builder.create();
      return dialog;
      }
  }
  </code></pre>
  
  <p>Android Studio's bugtracker function does not give any results, the exception is thrown via some system function whenever the Singleplayer button is pressed. There are no clues as of after which line of code I get the exception, but my best guess would be the show() method of AlertDialogFragment.</p>