title: Button click listener in fragment. Android studio
body: <p>I have a problem in trying to implement a button click listener in a fragment. I don't have a problem if there is just one button, but I have 3 buttons in the fragment UI. </p>
  
  <p>This is what I get: </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
  </code></pre>
  
  <p>The code, I made it as a public method </p>
  
  <pre><code>@Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
        // Inflate the layout for this fragment
         View view = inflater.inflate(R.layout.fragment_blank, container, false);
  
  
    first=(Button) view.findViewById(R.id.button_first);
    first.setOnClickListener(this);
    second=(Button) view.findViewById(R.id.button_second);
    second.setOnClickListener(this);
    third=(Button) view.findViewById(R.id.button_third);
    third.setOnClickListener(this);
  
    // Also I tried these ones but its not possible to :
    //first.setOnClickListener((View.OnClickListener) getActivity());
    //second.setOnClickListener((View.OnClickListener) getActivity());
    //third.setOnClickListener((View.OnClickListener) getActivity());
  
  
      return view;
  }
  
   @Override
      public void onClick(View view) {
  
      if (view.getId() == R.id.button_first) {
  
       //some code here
      }
      if (view.getId() == R.id.button_second) {
          //some code here
      }
      if (view.getId() == R.id.button_third) {
         //some code here
          }
   }
  </code></pre>
  
  <p>I can implements one buttons listener as follow: </p>
  
  <pre><code>@Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
         View view = inflater.inflate(R.layout.fragment_blank_fragment5, container, false);
  
  
    call= (Button) view.findViewById(R.id.button);
    call.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v)
       {
           dialContactPhone("Some phone number");
  
       }
  
   });
        return view;
   }
  </code></pre>
  
  <p>But I'd like to know what I'm doing wrong with the first code. Why there is a <code>null</code>?</p>