I am getting the following stack trace (below is a complete copy) , this gives me little or no indication as to where in a massive application it is when going wrong and user feedback is nothing beyond "It crashed".
Is there anything I can do to pinpoint this more ?
java.lang.NullPointerException at android.widget.ArrayAdapter.getCount(ArrayAdapter.java:291)
at android.widget.AdapterView.checkFocus(AdapterView.java:689)
at android.widget.AdapterView$AdapterDataSetObserver.onInvalidated(AdapterView.java:813)
at android.database.DataSetObservable.notifyInvalidated(DataSetObservable.java:43)
at android.widget.BaseAdapter.notifyDataSetInvalidated(BaseAdapter.java:54)
at android.widget.ArrayAdapter$ArrayFilter.publishResults(ArrayAdapter.java:469)
at android.widget.Filter$ResultsHandler.handleMessage(Filter.java:282)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4701)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Look at the code for ArrayAdapter.getCount():
/**
* {#inheritDoc}
*/
public int getCount() {
return mObjects.size();
}
Clearly mObjects is null, i.e. your ListView or other AdapterView-derived type is trying to use the adapter before you've initialized it with it's data.
What you could do is putting debug information before every call to getCount() using the Log class
Log.d("tag", "Trying to get count on line 50 class Test");
then open logcat and find the last entry of this log before the error occures. Then you have the right location of the crash.
Related
I have a null pointer exception somewhere, but I am not sure where. All I have is this error:
java.lang.NullPointerException
at android.widget.ArrayAdapter.getCount(ArrayAdapter.java:330)
at android.widget.AdapterView.checkFocus(AdapterView.java:700)
at android.widget.AdapterView$AdapterDataSetObserver.onInvalidated(AdapterView.java:823)
at android.widget.AbsListView$AdapterDataSetObserver.onInvalidated(AbsListView.java:5738)
at android.database.DataSetObservable.notifyInvalidated(DataSetObservable.java:47)
at android.widget.BaseAdapter.notifyDataSetInvalidated(BaseAdapter.java:59)
at android.widget.ArrayAdapter$ArrayFilter.publishResults(ArrayAdapter.java:513)
at android.widget.Filter$ResultsHandler.handleMessage(Filter.java:282)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4697)
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:787)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
at dalvik.system.NativeStart.main(Native Method)
Would anyone have any ideas for how to debug this? I have not been able to reproduce it. It just sometimes happens and shows up in my crash logs.
Thanks!
Here's the code for ArrayAdapter: https://github.com/android/platform_frameworks_base/blob/master/core/java/android/widget/ArrayAdapter.java.
Assuming this is the right version, an NPE on line 330 would be caused if the adapter's dataset (i.e. the backing list or array) is null.
Hope that helps.
I've been getting this error in my developer portal. I'm not sure why. Stack trace tracks back into some internal function call inside WebView object.
java.lang.NullPointerException
at android.webkit.WebView.loadUrlImpl(WebView.java:3008)
at android.webkit.WebView.loadUrlImpl(WebView.java:3047)
at android.webkit.WebView.loadUrl(WebView.java:3040)
at com.myapp.android.PreviewActivity.notifyJS(PreviewActivity.java:175)
at com.myapp.android.PreviewActivity.access$14(PreviewActivity.java:174)
at com.myapp.android.PreviewActivity$ActionBarItemClickListener.onClick(PreviewActivity.java:901)
at android.view.View.performClick(View.java:3644)
at android.view.View$PerformClick.run(View.java:14313)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4517)
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:993)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
at dalvik.system.NativeStart.main(Native Method)
In my code at com.myapp.android.PreviewActivity.notifyJS(PreviewActivity.java:175), there is this line
webView.loadUrl("javascript:MyApp.onClick('" + action + "');");
I'm actually invoking a javascript call from my java code. Has anyone faced this issue before?
I found the answer myself. If webView.destroy() has already been called then calling webView.loadUrl() will cause this exception.
It seems that your webview is null. Did you call findView before?
java.lang.NullPointerException
at com.surreall.yacht.yatzee.achievementsCheck`(yatzee.java:2031)`
at com.surreall.yacht.yatzee.gameOver(yatzee.java:1929)
at com.surreall.yacht.yatzee$4.onClick(yatzee.java:1250)
at android.view.View.performClick(View.java:2485)
at android.view.View$PerformClick.run(View.java:9080)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
at dalvik.system.NativeStart.main(Native Method)
obviously it is happening in the function achievementsCheck(), but no matter what i do i can't reproduce the null pointer exception. what does the "2031" mean in that line? can that tell me anything?
As per your question "what does the "2031" mean in that line?" It is the line number of the code on which the NullpointerException is generating. So look at that line it might be because of an object which is not initialized and has a null reference.
So for example if you have
Line 1: Object obj; //Note obj is not initialized here.
Line 2:
Line 3: //and you are trying to call
Line 4:
Line 5: obj.toString()///NullPointer will be generated here
You will see a NullPointerException generated at line 5
To solve this issue you will have to initialize obj correctly so in this case it will
Object obj = new Object();
The code: http://pastebin.com/5bhKULGd
the problem:
When you click an item in the gridview, OCLGenre (OnItemClickListener for Genre view)
fires an nullPointer at line 123. I'm trying to understand where the nullPointer comes from but can't find it.
The stack:
ERROR/AndroidRuntime(10511): FATAL EXCEPTION: main
java.lang.NullPointerException
at com.MMWeb.MMWeb$browse$1.onItemClick(MMWeb.java:123)
at android.widget.AdapterView.performItemClick(AdapterView.java:284)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Anyone got a pointer to where to find the source of this nullPointer?
If you try to access an object which is null. Like the below example.
ClassA objA;
At this time you have just declared this object but you have not initialized or instantiated it.
When you try to access any property or method in it, it will throw
NullPointerException.
Oke i found my problem By moving the ImageAdapter out of the "browse" class, the "browse" class did not have any reference to the ArrayList 'items'. I could find the problem because, after all, i defined the ArrayList at line 112. However, showGenres() uses a local ArrayList, and the ImageAdapter would put it in "browser.items". Fixed it by removing the local decleration of items on line 145, 154 and 162
I am using the latest version of AdWhirl to serve Ads from AdMob(+AdSense),InMobi,mdotm and Millennial Media. I am getting a lot of;
Exception class java.lang.NullPointerException
Source method AdWhirlLayout.handleAd()
Stack trace
java.lang.NullPointerException
at com.adwhirl.AdWhirlLayout.handleAd(AdWhirlLayout.java:217)
at com.adwhirl.AdWhirlLayout.access$3(AdWhirlLayout.java:205)
at com.adwhirl.AdWhirlLayout$HandleAdRunnable.run(AdWhirlLayout.java:390)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:132)
at android.app.ActivityThread.main(ActivityThread.java:4025)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)
This is causing a large amount of force closing and upsetting my users, does anyone have any ideas what is causing this and how to fix.
Any help gratefully received.
Thanks
AdWhirl has had a new release since this exception. Is anybody still seeing these errors? This may have been some weird case where there was a bad configuration that causes a Ration object to be populated with null values, which caused the NPE when a string was formatted with one of these fields. All the fields in the ration have a value by default.