-3

Errors...

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.vaidish.myapplication, PID: 12727
java.lang.IllegalStateException: Could not execute method for android:onClick
    at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
    at android.view.View.performClick(View.java:6256)
    at android.view.View$PerformClick.run(View.java:24697)
    at android.os.Handler.handleCallback(Handler.java:789)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6567)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
    at android.view.View.performClick(View.java:6256) 
    at android.view.View$PerformClick.run(View.java:24697) 
    at android.os.Handler.handleCallback(Handler.java:789) 
    at android.os.Handler.dispatchMessage(Handler.java:98) 
    at android.os.Looper.loop(Looper.java:164) 
    at android.app.ActivityThread.main(ActivityThread.java:6567) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources$Theme android.content.Context.getTheme()' on a null object reference
    at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:224)
    at android.app.AlertDialog$Builder.<init>(AlertDialog.java:454)
    at com.example.vaidish.myapplication.Background.<init>(Background.java:25)
    at com.example.vaidish.myapplication.MainActivity.userLogin(MainActivity.java:56)
    at java.lang.reflect.Method.invoke(Native Method) 
    at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
    at android.view.View.performClick(View.java:6256) 
    at android.view.View$PerformClick.run(View.java:24697) 
    at android.os.Handler.handleCallback(Handler.java:789) 
    at android.os.Handler.dispatchMessage(Handler.java:98) 
    at android.os.Looper.loop(Looper.java:164) 
    at android.app.ActivityThread.main(ActivityThread.java:6567) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
halfer
  • 18,701
  • 13
  • 79
  • 158
  • 2
    Can you post your code – Ravi Dec 20 '17 at 20:26
  • 2
    Possible duplicate of [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Zoe Dec 20 '17 at 20:29
  • We cannot help you without any code. If you want help, post code along with your question please. – Matthew Vanlandingham Dec 20 '17 at 21:05
  • [Too many duplicates to mention](https://stackoverflow.com/search?q=java.lang.IllegalStateException%3A+Could+not+execute+method+for+android%3AonClick). – halfer Dec 21 '17 at 00:04
  • Yes I can post my code...but now I found my mistake....so its solved!! BTW Thank you for your suggestion & help. – Vaidik Trivedi Dec 21 '17 at 06:48

1 Answers1

0

The root cause of your crash is this bit:

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources$Theme android.content.Context.getTheme()' on a null object reference
    at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:224)
    at android.app.AlertDialog$Builder.<init>(AlertDialog.java:454)
    at com.example.vaidish.myapplication.Background.<init>(Background.java:25)

This says that you're passing null to the AlertDialog.Builder constructor. You could be doing that explicitly, like:

new AlertDialog.Builder(null)

or you could be doing it unintentionally, like:

new AlertDialog.Builder(mContext)

Check line 25 of your Background class, and make sure you're passing a non-null Context instance to the builder.

Ben P.
  • 44,716
  • 5
  • 70
  • 96