title: Android NullPointerException when findViewById
body: <p>when i run my app i get this error in the log-cat:</p>
  
  <pre><code>Caused by: java.lang.NullPointerException
  at com.myfirstapp.myfirstapp.MainActivity.onCreate(MainActivity.java:52)
  at android.app.Activity.performCreate(Activity.java:5312)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1111)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2552)
  ... 11 more
  </code></pre>
  
  <p>Here's line 52:</p>
  
  <pre><code>String message = editTextInput.getText().toString();
  </code></pre>
  
  <p>So far i've worked out that the NPE must be when I define the EditText (or any view for that matter):</p>
  
  <pre><code>EditText editText = (EditText) findViewById(R.id.input_text);
  </code></pre>
  
  <p>However though, I don't get an NPE when I define a EditText without: <code>findViewById()</code> like this View:</p>
  
  <pre><code>TextView desc = new TextView(this);
  </code></pre>
  
  <p>Here is the entire <code>onCreate()</code> method:</p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      if (savedInstanceState == null) {
          getSupportFragmentManager().beginTransaction()
                  .add(R.id.container, new PlaceholderFragment())
                  .commit();
      }
  
      EditText editText = (EditText) findViewById(R.id.input_text);
      Button submit = (Button) findViewById(R.id.submit);
      LinearLayout layout = (LinearLayout) findViewById(R.id.layout_main);
      Intent intent = new Intent(this, testActivity.class);
      final TextView desc = new TextView(this);
      final TextView title = new TextView(this);
  
      String message = editText.getText().toString();
  
      submit.setVisibility(View.VISIBLE);
      submit.setOnClickListener(new OnClickListener() {
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              editText.setVisibility(View.GONE);}});
  
      desc.setTextSize(20);
      desc.setText(message);
      desc.setGravity(Gravity.LEFT | Gravity.TOP);
      desc.setPadding(5, 5, 5, 5);
      desc.setTextColor(getResources().getColor(R.color.black));
  
      title.setTextSize(10);
      title.setText(R.string.title_activity_dictionary);
      title.setGravity(Gravity.LEFT | Gravity.TOP);
      title.setPadding(5, 5, 5, 5);
      title.setTextColor(getResources().getColor(R.color.black));
  
      layout.addView(desc);
      layout.addView(title);
  }
  </code></pre>
  
  <p>What I dont get is why is there a NPE when I clearly define the View?</p>