title: Null object reference on Button Click
body: <p>I have a <code>listview</code>.On click of particular item of <code>listview</code>,i am opening a layout from bottom which has 3 buttons and on click of any of the 3 buttons i want to place a call,but when i click on any of the button i am getting null object reference even after creating objects of those button</p>
  
  <pre><code>public class CallActivity extends ListActivity {
  
      private Button sales,service,insurance;
  
      private static final String[] items={"Dahisar Brach","Borivali West ASC","Nagpada ASC"
              ,"Borivali East ASC","Kandivali West Workshop","Kandivali West"};
  
      @Override
      public void onCreate(Bundle icicle) {
          super.onCreate(icicle);
          setContentView(R.layout.activity_call);
  
          sales=findViewById(R.id.sales);
          service=findViewById(R.id.service);
          insurance=findViewById(R.id.insurance);
  
          setListAdapter(new ArrayAdapter&lt;String&gt;(this,
                  R.layout.list_items,
                  items));
  
      }
  
      @Override
      public void onListItemClick(ListView parent, View v, int position,
                                  long id) {
  
          final Dialog mBottomSheetDialog = new Dialog(CallActivity.this, R.style.MaterialDialogSheet);
          mBottomSheetDialog.setContentView(R.layout.view); // your custom view.
          mBottomSheetDialog.setCancelable(true);
          mBottomSheetDialog.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
          mBottomSheetDialog.getWindow().setGravity(Gravity.BOTTOM);
          mBottomSheetDialog.show();
  
          if(position==0){
              sales.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
                      Uri call = Uri.parse("tel:" + "02228921114");
                      Intent callNumber = new Intent(Intent.ACTION_DIAL, call);
                      callNumber = Intent.createChooser(callNumber, "Call Number");
                      startActivity(callNumber);
                  }
              });
  
              service.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
                      Uri call = Uri.parse("tel:" + "101");
                      Intent callNumber = new Intent(Intent.ACTION_DIAL, call);
                      callNumber = Intent.createChooser(callNumber, "Call Number");
                      startActivity(callNumber);
                  }
              });
  
  
              insurance.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
                      Uri call = Uri.parse("tel:" + "100");
                      Intent callNumber = new Intent(Intent.ACTION_DIAL, call);
                      callNumber = Intent.createChooser(callNumber, "Call Number");
                      startActivity(callNumber);
                  }
              });
          }
  
  
      }
  }
  </code></pre>
  
  <p>view(layout file)</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical" android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_gravity="bottom"&gt;
  
      &lt;TextView
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:text="To whom you want to call?"
          android:gravity="center"/&gt;
  
      &lt;Button
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_gravity="bottom"
          android:text="Sales"
          android:gravity="center"
          android:id="@+id/sales"
          /&gt;
      &lt;Button
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_gravity="bottom"
          android:text="Service"
          android:gravity="center"
          android:id="@+id/service"
          /&gt;
      &lt;Button
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_gravity="bottom"
          android:text="Insurance"
          android:id="@+id/insurance"
          android:gravity="center"
          /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>What am i doing wrong,Please help.I even tried creating the object in <code>onListItemClick</code> method,but i am getting the same error.
  FYI,
  I am using compile 'com.android.support:appcompat-v7:26.+', so i don't need to typecast my button</p>