0

My App is crashing on some devices for some users, I could not reproduce it though. But i can see the crash reports. I have listview which uses custom ArrayAdapter(extends android.widget.ArrayAdapter) on multiple places. I have no idea where it is happening and how. Crash logs says NullPointerException but not pointing where it is actually happening in my code. Somebody please help me in figuring this out. Here is the logs

java.lang.NullPointerException
        at android.widget.ArrayAdapter.getCount(ArrayAdapter.java:330)
        at android.widget.HeaderViewListAdapter.getCount(HeaderViewListAdapter.java:132)
        at android.widget.ListView.onMeasure(ListView.java:1155)
        at android.view.View.measure(View.java:17387)
        at android.support.v4.widget.SwipeRefreshLayout.onMeasure(SwipeRefreshLayout.java:353)
        at android.view.View.measure(View.java:17387)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5353)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
        at android.view.View.measure(View.java:17387)
        at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:719)
        at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455)
        at android.view.View.measure(View.java:17387)
        at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:762)
        at android.view.View.measure(View.java:17387)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5353)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
        at android.view.View.measure(View.java:17387)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5353)
        at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:391)
        at android.view.View.measure(View.java:17387)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5353)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
        at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2533)
        at android.view.View.measure(View.java:17387)
        at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2214)
        at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1351)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1550)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1235)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6472)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
        at android.view.Choreographer.doCallbacks(Choreographer.java:603)
        at android.view.Choreographer.doFrame(Choreographer.java:573)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
        at android.os.Handler.handleCallback(Handler.java:733)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:157)
        at android.app.ActivityThread.main(ActivityThread.java:5356)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
        at dalvik.system.NativeStart.main(Native Method)
7
  • Post code of class HeaderViewListAdapter Commented Mar 12, 2015 at 8:46
  • The error seems to be in getCount function in your adapter .. make sure it returns the right count and your array is not null and post your adapter code . Commented Mar 12, 2015 at 8:47
  • 3
    the list or array of objects you are passing to the super constructor of array adapter is null. Commented Mar 12, 2015 at 8:49
  • 1
    You didn't initialize your string array. Commented Mar 12, 2015 at 9:18
  • 1
    Initilaize the list or array Commented Mar 12, 2015 at 9:21

1 Answer 1

1

Thank you Blackbelt for your answer. That was the exact reason behind the issue. The array of object I was passing to the super constructor of array adapter was null. I was saving it in a static array and it was becoming null somehow in some scenarios. Initializing the array again solved my problem.

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

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.