Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arrayadapter.getcount null point exception

Tags:

arrays

android

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)
like image 909
Chris Avatar asked Feb 22 '11 09:02

Chris


Video Answer


1 Answers

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.

like image 98
Reuben Scratton Avatar answered Oct 21 '22 09:10

Reuben Scratton