0

my android app is crashing when i get to an activity named "finalizar" and I dont understand the crash log. this activity is kind of the leaderboard (dunno if that helps)

E/AndroidRuntime: FATAL EXCEPTION: main
              Process: com.example.nico.quimiquiz, PID: 1198
              java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.nico.quimiquiz/com.example.nico.quimiquiz.finalizar}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2679)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
                  at android.app.ActivityThread.-wrap11(Unknown Source:0)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
                  at android.os.Handler.dispatchMessage(Handler.java:106)
                  at android.os.Looper.loop(Looper.java:164)
                  at android.app.ActivityThread.main(ActivityThread.java:6494)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:440)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
               Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
                  at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:117)
                  at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:149)
                  at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:56)
                  at android.support.v7.app.AppCompatDelegateImplV23.<init>(AppCompatDelegateImplV23.java:31)
                  at android.support.v7.app.AppCompatDelegateImplN.<init>(AppCompatDelegateImplN.java:31)
                  at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:198)
                  at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:183)
                  at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:519)
                  at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:190)
                  at com.example.nico.quimiquiz.finalizar.<init>(finalizar.java:93)
                  at java.lang.Class.newInstance(Native Method)
                  at android.app.Instrumentation.newActivity(Instrumentation.java:1175)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2669)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) 
                  at android.app.ActivityThread.-wrap11(Unknown Source:0) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) 
                  at android.os.Handler.dispatchMessage(Handler.java:106) 
                  at android.os.Looper.loop(Looper.java:164) 
                  at android.app.ActivityThread.main(ActivityThread.java:6494) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:440) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
  • i can post the java code if nesesary – nico casto Apr 03 '18 at 01:49
  • You can't call `findViewById()` in a field initializer; i.e., outside of a class method. Move those calls into `onCreate()`, after the `setContentView()` call. – Mike M. Apr 03 '18 at 01:49
  • i cant move my variables to a method because they are called in two different methods – nico casto Apr 03 '18 at 01:51
  • I didn't say to move the declarations; only the `findViewById()` calls. Have a look at [this answer](https://stackoverflow.com/a/36666266) on the first linked duplicate. – Mike M. Apr 03 '18 at 01:53

0 Answers0