Prathap Badavath
Prathap Badavath

Reputation: 1671

java.lang.IllegalStateException: You need to use a Theme.AppCompat theme with this activity

When I create alert dialog with appcompat it shows following error:

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:309)
at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:278)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:252)
at android.support.v7.app.AppCompatDialog.setContentView(AppCompatDialog.java:76)
at android.support.v7.app.AlertController.installContent(AlertController.java:216)
at android.support.v7.app.AlertDialog.onCreate(AlertDialog.java:240)
at android.app.Dialog.dispatchOnCreate(Dialog.java:373)
at android.app.Dialog.show(Dialog.java:274)
at com.altiux.sharedpre.LoginActivity$1.onClick(LoginActivity.java:30)
at android.view.View.performClick(View.java:4756)
at android.view.View$PerformClick.run(View.java:19749)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
11-04 01:51:50.868 8765-8765/? I/Process: Sending signal. PID: 8765 SIG: 9

Upvotes: 1

Views: 395

Answers (1)

Prathap Badavath
Prathap Badavath

Reputation: 1671

Finally I got the solution.
When we call AlertDialog.Builder we have to pass current activity context. Following is the syntax.

AlertDialog.Builder builder = new AlertDialog.Builder(CurrentActivity.this);

Upvotes: 1

Related Questions