title: OnClickListener on a null object reference
body: <p>Hello can anybody help me to handle this error: </p>
  
  <pre><code>java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
  at de.kwietzorek.fulcrumwebview.MainActivity$AddServerFragment.onCreateView(MainActivity.java:141)
  </code></pre>
  
  <p>141 is at <code>btn_back.setOnClickListener(new View.OnClickListener() {</code></p>
  
  <p><strong>Fragment: AddServerFragement</strong></p>
  
  <pre><code>public class AddServerFragment extends Fragment
          implements View.OnClickListener {
  
      @Override
          public void onClick(View view) {
          }
  
      public AddServerFragment(){
      }
  
      Button btn_back, btn_add;
      EditText server_ip, server_name;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.add_ip, container, false);
  
          server_ip = (EditText) findViewById(R.id.edit_server_address);
          server_name = (EditText) findViewById(R.id.edit_server_name);
  
          btn_back = (Button) findViewById(R.id.btn_back);
          btn_back.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View view) {
                  Intent intent = new Intent(getApplicationContext(), MainActivity.class);
                  startActivity(intent);
              }
          });
  
          btn_add = (Button) findViewById(R.id.btn_add);
          btn_add.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  String new_server_ip = null, new_server_name = null;
  
                  ArrayList&lt;String&gt; server_name_list = new ArrayList&lt;String&gt;();
                  ArrayList&lt;String&gt; server_ip_list = new ArrayList&lt;String&gt;();
  
                  new_server_ip = server_ip.getText().toString();
                  server_ip_list.add(new_server_ip);
  
                  new_server_name = server_name.getText().toString();
                  server_name_list.add(new_server_name);
              }
          });
  
          return view;
      }
  }
  </code></pre>