title: Unfortunately, *GridView* has stopped
body: <p>I was implementing GridView method. Everything went great and showed a grid of eight images as per my code but then I added a code which upon clicking an image would display some dialog with two buttons. However when I executed the full code, the app rendered a problem as captioned above. I have included the code and if anything you find missing, please comment below, I'll paste that too. Please help!</p>
  
  <p>Styles.xml:</p>
  
  <pre><code>&lt;resources&gt;
  
  &lt;!-- Base application theme. --&gt;
  &lt;style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"&gt;
      &lt;!-- Customize your theme here. --&gt;
      &lt;item name="colorPrimary"&gt;@color/colorPrimary&lt;/item&gt;
      &lt;item name="colorPrimaryDark"&gt;@color/colorPrimaryDark&lt;/item&gt;
      &lt;item name="colorAccent"&gt;@color/colorAccent&lt;/item&gt;
  &lt;/style&gt;
  </code></pre>
  
  <p></p>
  
  <p>AndroidManifest.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:supportsRtl="true"
      android:theme="@style/AppTheme"&gt;
      &lt;activity android:name=".MainActivity"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;activity android:name=".MyDialog"
          android:theme="@android:style/Theme.Dialog"
          android:label="ShubhApplication"&gt;&lt;/activity&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p></p>
  
  <p>MyDialog.java:</p>
  
  <pre><code>package com.shubham.gridview;
  
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.View;
  
  public class MyDialog extends AppCompatActivity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_my_dialog);
  }
  
  public void closeDialog(View v){
  
      finish();
  }
  
  public void closeDialog2(View v){
  
      finish();
  }
  }
  </code></pre>
  
  <p>MainActivity.java:</p>
  
  <pre><code>package com.shubham.gridview;
  
  import android.content.Context;
  import android.content.Intent;
  import android.content.res.Resources;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.AdapterView;
  import android.widget.BaseAdapter;
  import android.widget.GridView;
  import android.widget.ImageView;
  
  import java.util.ArrayList;
  
  public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
  
  
  GridView myGrid;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      myGrid = (GridView) findViewById(R.id.gridView);
      myGrid.setAdapter(new ShubhAdapter(this));
  
      myGrid.setOnItemClickListener(this);
  
  
  }
  
  @Override
  public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
  
      Intent intent = new Intent(this, MyDialog.class);
      startActivity(intent);
  }
  }
  
  class City
  {
      int imageId;
  String cityName;
  
  City(int imageId, String cityName)
  {
      this.imageId = imageId;
      this.cityName = cityName;
  
  }
  }
  
  class ShubhAdapter extends BaseAdapter
  {
  
  ArrayList&lt;City&gt; list;
  Context context;
  ShubhAdapter(Context context)
  {
      this.context = context;
      list = new ArrayList&lt;City&gt;();
      Resources res = context.getResources();
      String[] tempCityNames = res.getStringArray(R.array.city_names);
      int[] cityImages = { R.drawable.ahmedabad, R.drawable.bangalore, R.drawable.chennai,
                          R.drawable.delhi, R.drawable.hyderabad, R.drawable.kolkata,
                          R.drawable.lucknow, R.drawable.mumbai};
  
      for (int i=0; i&lt;8; i++)
      {
          City tempCity = new City(cityImages[i], tempCityNames[i]);
          list.add(tempCity);
      }
  }
  
  @Override
  public int getCount() {
      return list.size();
  }
  
  @Override
  public Object getItem(int i) {
      return list.get(i);
  }
  
  @Override
  public long getItemId(int i) {
      return i;
  }
  
  class ViewHolder
  {
      ImageView myCity;
      ViewHolder(View v)
      {
          myCity = (ImageView) v.findViewById(R.id.imageView);
  
      }
  }
  @Override
  public View getView(int i, View convertView, ViewGroup parent) {
  
      View row = convertView;
      ViewHolder holder = null;
  
      if(row == null)
      {
          LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          row = inflater.inflate(R.layout.single_item, parent, false);
          holder = new ViewHolder(row);
          row.setTag(holder);
      }
  
      else
      {
          holder = (ViewHolder) row.getTag();
      }
  
      City temp = list.get(i);
      holder.myCity.setImageResource(temp.imageId);
  
      return row;
  }
  }
  </code></pre>
  
  <p>logcat:</p>
  
  <pre><code>02-27 22:35:29.721 4972-4972/com.shubham.gridview E/AndroidRuntime: FATAL           EXCEPTION: main
                                                                  Process: com.shubham.gridview, PID: 4972
                                                                  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.shubham.gridview/com.shubham.gridview.MyDialog}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2389)
                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2441)
                                                                      at android.app.ActivityThread.access$900(ActivityThread.java:151)
                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
                                                                      at android.os.Handler.dispatchMessage(Handler.java:110)
                                                                      at android.os.Looper.loop(Looper.java:193)
                                                                      at android.app.ActivityThread.main(ActivityThread.java:5345)
                                                                      at java.lang.reflect.Method.invokeNative(Native Method)
                                                                      at java.lang.reflect.Method.invoke(Method.java:515)
                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828)
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
                                                                      at dalvik.system.NativeStart.main(Native Method)
                                                                   Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
                                                                      at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:343)
                                                                      at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:312)
                                                                      at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:277)
                                                                      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                                                                      at com.shubham.gridview.MyDialog.onCreate(MyDialog.java:12)
                                                                      at android.app.Activity.performCreate(Activity.java:5343)
                                                                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2343)
                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2441) 
                                                                      at android.app.ActivityThread.access$900(ActivityThread.java:151) 
                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) 
                                                                      at android.os.Handler.dispatchMessage(Handler.java:110) 
                                                                      at android.os.Looper.loop(Looper.java:193) 
                                                                      at android.app.ActivityThread.main(ActivityThread.java:5345) 
                                                                      at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                      at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828) 
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644) 
                                                                      at dalvik.system.NativeStart.main(Native Method) 
  02-27 22:40:29.756 4972-4972/com.shubham.gridview I/Process: Sending signal. PID: 4972 SIG: 9
  </code></pre>