title: how to add spinner in a custom dialog box and populate it with array
body: <p>i have main screen which have a button called menu on click of menu  i am opening a custom dialog box in which there is a spinner 
  i want to populate this by using array
  all is working fine but when i am setting adapter to the spinner it shows me error</p>
  
  <p>this what i am doing in android , </p>
  
  <pre><code>package com.example.drydays;
  import java.util.ArrayList;
  
  import android.os.Bundle;
  import android.app.Activity;
  import android.app.Dialog;
  import android.content.Context;
  import android.content.pm.ActivityInfo;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.view.Window;
  import android.view.WindowManager;
  import android.widget.ArrayAdapter;
  import android.widget.Button;
  import android.widget.ImageView;
  import android.widget.Spinner;
  
  public class MainActivity extends Activity {
       final Context context = this;
       private Button button;
  
       private String[] states  = new String[]{
                  "Gujrat","Jammu and Kashmir","Kerala","Karnataka","Lakshadweep","Maharashtra","Manipur","Mizoram",
                  "Nagaland","New Delhi","Rajasthan","Tami Nadu","West Bengal"
          };
       ArrayList&lt;String&gt; categoryList = new ArrayList&lt;String&gt;();
  
       @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          //make it fullscreen
                  requestWindowFeature(Window.FEATURE_NO_TITLE);      
                  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                  WindowManager.LayoutParams.FLAG_FULLSCREEN);
  
          //fix portrait orientation
                  setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  
          setContentView(R.layout.activity_main);
          ImageView img = (ImageView)findViewById(R.id.imageView1);
          img.setOnClickListener(new OnClickListener() {
  
                @Override
                public void onClick(View arg0) {
  
                  // custom dialog
                  final Dialog dialog = new Dialog(context);
                  dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                  dialog.setContentView(R.layout.menu);
                  Button dialogButton = (Button) dialog.findViewById(R.id.btncross);
                  // if button is clicked, close the custom dialog
                  dialogButton.setOnClickListener(new OnClickListener() {
                      @Override
                      public void onClick(View v) {
                          dialog.dismiss();
                      }
                  });
  
                  dialog.show();
                }
              });
  
           Spinner spin = (Spinner)findViewById(R.id.spinState);
           ArrayAdapter&lt;String&gt; adapter_state = new ArrayAdapter&lt;String&gt;(MainActivity.this,  android.R.layout.simple_spinner_item, states);
           adapter_state.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
           **spin.setAdapter(adapter_state);**
           // adding this line gives me error
      }
  
  }
  </code></pre>