title: How can I fix this error: You need to use a Theme.AppCompat theme (or descendant) with this activity
body: <p>I searched all internet web sites to fix this error, but I couldn't. I just want to create AlertDialog with two button Yes and No.</p>
  
  <p>This is my code:</p>
  
  <pre><code>import android.content.DialogInterface;
  import android.support.v7.app.AlertDialog;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  
  public class DialogActivity extends AppCompatActivity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_dialog);
  
      Button btnDialog= (Button) findViewById(R.id.btnDialog);
      btnDialog.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              showDialogMessage();
          }
      });
  }
  
  private void showDialogMessage(){
  
      AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
      // Add the buttons
      builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int id) {
              // User clicked OK button
          }
      });
      builder.setNegativeButton("NO", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int id) {
              // User cancelled the dialog
          }
      });
  
      AlertDialog dialog = builder.create();
      dialog.show();
  }
  }
  </code></pre>
  
  <p>And this is my Style:</p>
  
  <pre><code>&lt;resources&gt;
  
  &lt;!-- Base application theme. --&gt;
  &lt;style name="AppTheme" parent="AppTheme.Base"&gt;
      &lt;!-- Customize your theme here. --&gt;
  &lt;/style&gt;
  
  &lt;style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar"&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>this is my style(v21):</p>
  
  
  
  <pre><code>&lt;resources&gt;
  &lt;!-- extend one of the Theme.AppCompat themes --&gt;
  &lt;style name="AppTheme" parent="AppTheme.Base"&gt;
      &lt;!-- customize the color palette --&gt;
      &lt;item name="android:colorPrimary"&gt;@color/colorPrimary&lt;/item&gt;
      &lt;item name="android:colorPrimaryDark"&gt;@color/colorPrimaryDark&lt;/item&gt;
      &lt;item name="android:colorAccent"&gt;@color/colorAccent&lt;/item&gt;
      &lt;item name="android:windowTranslucentStatus"&gt;true&lt;/item&gt;
      &lt;item name="android:colorControlHighlight"&gt;@color/colorHighLight&lt;/item&gt;
  &lt;/style&gt;
  &lt;/resources&gt;
  </code></pre>
  
  <p>this is manifest:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.saly.rastari" &gt;   
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name=".DialogActivity"
              android:label="@string/title_activity_test"
              android:screenOrientation="portrait" &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;/application&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p>When I click on Dialog button I get this error:</p>
  
  <pre><code>11-02 04:36:55.941 24352-24352/? E/AndroidRuntime: FATAL EXCEPTION: main
  11-02 04:36:55.941 24352-24352/? E/AndroidRuntime: Process: com.irannara.pda.pdaassistant, PID: 24352
  11-02 04:36:55.941 24352-24352/? E/AndroidRuntime: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
  11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:309)
  11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:278)
  11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:252)
  11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at android.support.v7.app.AppCompatDialog.setContentView(AppCompatDialog.java:76)
  11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at android.support.v7.app.AlertController.installContent(AlertController.java:216)
  11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at android.support.v7.app.AlertDialog.onCreate(AlertDialog.java:240)
  11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at android.app.Dialog.dispatchOnCreate(Dialog.java:373)
  11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at android.app.Dialog.show(Dialog.java:274)
  11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at com.irannara.pda.pdaassistant.DialogActivity.showDialogMessage(DialogActivity.java:42)
  11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at com.irannara.pda.pdaassistant.DialogActivity.access$000(DialogActivity.java:10)
  11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at com.irannara.pda.pdaassistant.DialogActivity$1.onClick(DialogActivity.java:21)
  11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at android.view.View.performClick(View.java:4780)
  11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at android.view.View$PerformClick.run(View.java:19866)
  11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:739)
  11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:95)
  11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:135)
  11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5254)
  11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
  11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:372)
  11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
  11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
  11-02 04:36:55.959 718-718/? E/EGL_emulation: tid 718: eglCreateSyncKHR(1209): error 0x3004 (EGL_BAD_ATTRIBUTE)
  </code></pre>
  
  <p>none of this links couldn't help me:</p>
  
  <ul>
  <li><p><a href="https://stackoverflow.com/questions/21814825/you-need-to-use-a-theme-appcompat-theme-or-descendant-with-this-activity">You need to use a Theme.AppCompat theme (or descendant) with this activity</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/18063395/actionbarcompat-java-lang-illegalstateexception-you-need-to-use-a-theme-appcom">ActionBarCompat: java.lang.IllegalStateException: You need to use a Theme.AppCompat</a></p></li>
  <li><p><a href="https://teamtreehouse.com/community/need-to-use-a-themeappcompat-theme-or-descendant-with-this-activity" rel="noreferrer">Need to use a Theme.AppCompat theme (or descendant) with this activity???</a></p></li>
  </ul>
  
  <p>and more.</p>
  
  <p>how can i fix this?</p>