12

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)

2 Answers 2

10

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks, there is one adapter where I forgot to add a check, will add it and hopefully it will go away. No idea why I didn't think of that - sometimes you need that fresh pair of eyes
No worries. Note that the call comes in response to a Handler, suggesting a background thread is maybe signalling the UI thread when it shouldn't.
@ReubenScratton: The link was not working. Corrected it, please check.
@ReubenScratton actually i am getting similar error, Could you elaborate more :(
There's nothing more I can add. Look to where your adapter is initialized and ensure that it is set up correctly before any view code tries to use it.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.