title: Android custom dialog force close issue
body: <p>I'm trying to implement a custom dialog which contains a ListView. The objective is to display the dialog on a button click. For this, I'm creating a custom layout for my dialog and setting the content view on button click. For some unknown reason, the app is getting force closed. Can anybody tell me what am I doing wrong? Here are the code snippets:
  Main Activity:</p>
  
  <pre><code>package com.example.zdialog;
  
  import android.app.Activity;
  import android.app.Dialog;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.ArrayAdapter;
  import android.widget.Button;
  import android.widget.ListView;
  
  public class MainActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          final String[] myList={"book", "table", "car", "bag", "fridge",
                  "television", "radio"};
          Button btn=(Button)findViewById(R.id.button1);
          ListView lv=(ListView)findViewById(R.id.listView1);
          ArrayAdapter&lt;String&gt; aa=new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, myList);
          lv.setAdapter(aa);
  
          btn.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  Dialog dialog=new Dialog(MainActivity.this);
                  dialog.setContentView(R.layout.dialog_layout);
                  dialog.show();
  
              }
          }); 
      }
  }
  </code></pre>
  
  <p>activity_main.xml</p>
  
  <pre><code>    &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context=".MainActivity" &gt;
  
      &lt;TextView
          android:id="@+id/textView1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/hello_world" /&gt;
  
      &lt;Button
          android:id="@+id/button1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_alignParentRight="true"
          android:layout_below="@+id/textView1"
          android:layout_marginTop="17dp"
          android:text="Show Dialog" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>dialog_layout.xml:</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent" &gt;
  
      &lt;ListView
          android:id="@+id/listView1"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_alignParentTop="true" &gt;
  
      &lt;/ListView&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>As you can see, the custom dialog contains a simple ListView. I know, there are other methods for implementing list based dialogs, but I just want to know what's wrong with this code (learning Android programming on my own). Please help!</p>