title: java.lang.RuntimeException: Unable to start activity
body: <p>My app always crashes when i start it. This is the error on the Android Monitor. The following code is from my fragment which should start on the beginning of the app:</p>
  
  <pre><code>01-30 23:42:55.281 5767-5767/silverbeach.meintieralter E/AndroidRuntime: FATAL EXCEPTION: main
                                                                           Process: silverbeach.meintieralter, PID: 5767
                                                                           java.lang.RuntimeException: Unable to start activity ComponentInfo{silverbeach.meintieralter/silverbeach.meintieralter.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
                                                                               at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3254)
                                                                               at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350)
                                                                               at android.app.ActivityThread.access$1100(ActivityThread.java:222)
                                                                               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795)
                                                                               at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                               at android.os.Looper.loop(Looper.java:158)
                                                                               at android.app.ActivityThread.main(ActivityThread.java:7229)
                                                                               at java.lang.reflect.Method.invoke(Native Method)
                                                                               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
                                                                            Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
                                                                               at silverbeach.meintieralter.FragmentOne.onCreate(FragmentOne.java:36)
                                                                               at android.app.Fragment.performCreate(Fragment.java:2242)
                                                                               at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:947)
                                                                               at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1163)
                                                                               at android.app.BackStackRecord.run(BackStackRecord.java:793)
                                                                               at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1552)
                                                                               at android.app.FragmentController.execPendingActions(FragmentController.java:325)
                                                                               at android.app.Activity.performStart(Activity.java:6914)
                                                                               at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3217)
                                                                               at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350) 
                                                                               at android.app.ActivityThread.access$1100(ActivityThread.java:222) 
                                                                               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795) 
                                                                               at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                               at android.os.Looper.loop(Looper.java:158) 
                                                                               at android.app.ActivityThread.main(ActivityThread.java:7229) 
                                                                               at java.lang.reflect.Method.invoke(Native Method) 
                                                                               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                                                                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
  01-30 23:42:55.401 5767-5767/silverbeach.meintieralter I/Process: Sending signal. PID: 5767 SIG: 9
  </code></pre>
  
  <p><strong>code</strong></p>
  
  <pre><code> package silverbeach.meintieralter;
  
  import android.app.Fragment;
  import android.content.Context;
  import android.os.Bundle;
  import android.os.Vibrator;
  import android.support.annotation.Nullable;
  import android.support.design.widget.Snackbar;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.Spinner;
  import android.widget.TextView;
  import android.view.View.OnClickListener;
  
  import static android.content.Context.VIBRATOR_SERVICE;
  
  public class FragmentOne extends Fragment {
  
  private TextView out;
  private EditText alter;
  private Spinner s;
  private Button button;
  
  
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
  
  
      button.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
  
  
  
              String text = s.getSelectedItem().toString();
              int newage = 404;
              double doublenewage = 4.04;
              double doubleage;
              int intage;
              doubleage = Double.parseDouble(alter.getText().toString());
              intage = (int) doubleage;
  
              switch (text) {
                  case "Pferd": {
                      doublenewage = intage / 3.1;
                      long longpferdage = Math.round(doublenewage);
                      newage = (int) longpferdage;
  
                      if (newage &lt; 31)
                          out.setText("Du bist ein " + Integer.toString(newage) + " Jahre altes Pferd");
                      else
                          out.setText("Du bist höchstwahrscheinlich schon tot, aber theoretisch wärst du ein " + newage + "-Jähriges Pferd.");
                  }break;
                  case "Hund": {
                      newage = intage / 7;
                      if (newage &lt; 15)
  
                          out.setText("Du bist ein " + Integer.toString(newage) + " Jahre alter Hund.");
                      else
                          out.setText("Du bist höchstwahrscheinlich schon tot, aber theoretisch wärst du ein " + newage + "-Jähriger Hund.");
  
                  }break;
                  case "Meerschweinchen": {
                      newage = intage / 12;
                      if (newage &lt; 8)
  
                          //out.setText("Du bist ein " + Integer.toString(newage) + " Jahre altes Meerie.");
  
                          out.setText( "Du bist ein "+Integer.toString(newage)+" Jahre altes Meerie.");
  
  
  
  
  
                      else
                          out.setText("Du bist höchstwahrscheinlich schon tot, aber theoretisch wärst du ein " + newage + "-Jähriges Meerie.");
  
                  }break;
  
  
              }
  
  
  
          }
  
  
      });
  
  }
  
  
  
  
  
  @Nullable
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
      View layout = inflater.inflate(R.layout.fragment_one, null);
  
       out = (TextView) layout.findViewById(R.id.out);
       alter = (EditText) layout.findViewById(R.id.altereingabe);
       s = (Spinner) layout.findViewById(R.id.spinner);
       button = (Button) layout.findViewById(R.id.button);
  
     // tvText1 = (TextView) layout.findViewById(R.id.tvFragmentOne);
  
      return layout;
  }
  
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
      super.onActivityCreated(savedInstanceState);
  
      //tvText1.setText("Ok View 1 wurde geändert.");
  
  }
  </code></pre>
  
  <p>}</p>