This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 5 years ago.
01-02 05:30:50.220 8776-8776/com.wordpress.alhazn.puhaba E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.wordpress.alhazn.puhaba/com.wordpress.alhazn.puhaba.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2045)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2146)
at android.app.ActivityThread.access$700(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1238)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:177)
at android.app.ActivityThread.main(ActivityThread.java:4944)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
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.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:29)
at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:54)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:202)
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.wordpress.alhazn.puhaba.MainActivity.<init>(MainActivity.java:44)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1319)
at android.app.Instrumentation.newActivity(Instrumentation.java:1068)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2036)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2146)
at android.app.ActivityThread.access$700(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1238)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:177)
at android.app.ActivityThread.main(ActivityThread.java:4944)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)
Move your findViewById() calls later in the activity lifecycle. Not in <init> i.e. constructor/field initialization but rather e.g. onCreate() after you've also called setContentView().
Related
Usb debugging in my mobile has stopped working. The application is not installing via USB.Earlier It was working fine.I am attaching logs. Please help me to find out error.
FATAL EXCEPTION: main
java.lang.ExceptionInInitializerError
at
android.support.v4.app.SupportActivity.(SupportActivity.java:96)
at
android.support.v4.app.BaseFragmentActivityApi14.(BaseFragmentActivityApi14.java:28)
at
android.support.v4.app.BaseFragmentActivityApi16.(BaseFragmentActivityApi16.java:34)
at
android.support.v4.app.FragmentActivity.(FragmentActivity.java:67)
at
android.support.v7.app.AppCompatActivity.(AppCompatActivity.java:61)
at com.kpfactors_mbl.bizfactors.Login.(Login.java:68)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1319)
at android.app.Instrumentation.newActivity(Instrumentation.java:1068)
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2025)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
at android.app.ActivityThread.access$700(ActivityThread.java:140)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.UnsatisfiedLinkError: Cannot load library:
reloc_library[1307]: 1842 cannot locate '__isnanf'...at
java.lang.Runtime.loadLibrary(Runtime.java:370)
at java.lang.System.loadLibrary(System.java:535)
at
com.android.tools.profiler.support.ProfilerService.(ProfilerService.java:41)
at
android.support.v4.app.SupportActivity.(SupportActivity.java:96)
at
android.support.v4.app.BaseFragmentActivityApi14.(BaseFragmentActivityApi14.java:28)
at
android.support.v4.app.BaseFragmentActivityApi16.(BaseFragmentActivityApi16.java:34)
at
android.support.v4.app.FragmentActivity.(FragmentActivity.java:67)
at
android.support.v7.app.AppCompatActivity.(AppCompatActivity.java:61)
at com.kpfactors_mbl.bizfactors.Login.(Login.java:68)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1319)
at android.app.Instrumentation.newActivity(Instrumentation.java:1068)
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2025)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
at android.app.ActivityThread.access$700(ActivityThread.java:140)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method)
I have received this error in my remote app crash reporter:
java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
at android.view.WindowManagerGlobal.closeAll(WindowManagerGlobal.java:325)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3590)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3756)
at android.app.ActivityThread.access$800(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1286)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5279)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Is this a known bug in Android? I have no more information about the crash. Do you have any idea about what can I do to get the cause?
Array index start at 0
you have to subsract 1
My App crash rarely
i want to get off this bug for ever.
this is the log that users Report
i tried so long on this but nothing helps
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx.xxx/com.xxx.xxx.Master_}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2072)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2097)
at android.app.ActivityThread.access$600(ActivityThread.java:136)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4787)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.xxx.xxx.HomeFragment.onActivityCreated(HomeFragment.java:140)
at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:1508)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:958)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1097)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1895)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:566)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1163)
at android.app.Activity.performStart(Activity.java:5018)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2045)
... 11 more
I have a very basic activity with an ImageView of android:id="#+id/imageViewTest"
and then in the OnCreate method calling:
ImageView imageView = (ImageView)findViewById(R.id.imageViewTest);
// Set the background color to white
imageView.setBackgroundColor(Color.WHITE);
this gives error:
10-15 16:36:27.552 29097-29097/org.explore.self.beginner D/dalvikvm﹕ Late-enabling CheckJNI
10-15 16:36:28.017 29097-29097/org.explore.self.beginner D/AndroidRuntime﹕ Shutting down VM
10-15 16:36:28.017 29097-29097/org.explore.self.beginner W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41d9b2a0)
10-15 16:36:28.042 29097-29097/org.explore.self.beginner E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.explore.self.beginner/org.selfexplore.android.view.activity.TestActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
at android.app.ActivityThread.access$700(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at org.selfexplore.android.view.activity.TestActivity.onCreate(TestActivity.java:37)
at android.app.Activity.performCreate(Activity.java:5188)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
at android.app.ActivityThread.access$700(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)
10-15 16:36:28.062 29097-29097/org.explore.self.beginner I/Process﹕ Sending signal. PID: 29097 SIG: 9
But when I do a
ImageView imageView = new ImageView(this);
it works fine, Why?
PS: I am not able to add the layout code here, so sharing it in this doc: https://docs.google.com/document/d/1fbi3B_hAYUh_C2IwPfInvZ-BG2bgsa4pZoJKj8NBT9o/edit?usp=sharing
Your layout you've set with setContentView() doesn't have a view with id imageViewTest and findViewById() returns null, or you haven't called setContentView() at all.
While the Android app is working normally on most devices, for some people this error occurs on Galaxy S4:
java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
at android.view.WindowManagerGlobal.closeAll(WindowManagerGlobal.java:325)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3589)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3755)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1287)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5293)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Does anyone know how to deal with this?