Weird NPE on the headerView #88

Open
AndroidDeveloperLB opened this Issue Jan 28, 2014 · 4 comments

2 participants

@AndroidDeveloperLB

I'm trying to use this library and it seems to work fine, but on some devices (nexus 4 and SGS3, both with Android 4.3), when I scroll I get NPE.

for now, for each of the headerViews I use a simple TextView, as such:

@Override
public View getHeaderView(final int position, final View convertView, final ViewGroup parent) {
    TextView rootView = (TextView) convertView;
    if (rootView == null)
        rootView = new TextView(mContext);
    rootView.setText("pos:" + position); //NPE here?!
    return rootView;
}

and yet when I scroll down on those devices, I get this in the log:

01-28 14:00:38.484: E/AndroidRuntime(13778): FATAL EXCEPTION: main
01-28 14:00:38.484: E/AndroidRuntime(13778): java.lang.NullPointerException
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.widget.TextView.checkForRelayout(TextView.java:6466)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.widget.TextView.setText(TextView.java:3764)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.widget.TextView.setText(TextView.java:3622)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.widget.TextView.setText(TextView.java:3597)
01-28 14:00:38.484: E/AndroidRuntime(13778): at com.syncme.activities.main_activity.fragment_album_chooser.AlbumsAdapter.getHeaderView(AlbumsAdapter.java:210)
01-28 14:00:38.484: E/AndroidRuntime(13778): at com.tonicartos.widget.stickygridheaders.StickyGridHeadersSimpleAdapterWrapper.getHeaderView(StickyGridHeadersSimpleAdapterWrapper.java:59)
01-28 14:00:38.484: E/AndroidRuntime(13778): at com.tonicartos.widget.stickygridheaders.StickyGridHeadersBaseAdapterWrapper.getHeaderView(StickyGridHeadersBaseAdapterWrapper.java:293)
01-28 14:00:38.484: E/AndroidRuntime(13778): at com.tonicartos.widget.stickygridheaders.StickyGridHeadersGridView.scrollChanged(StickyGridHeadersGridView.java:717)
01-28 14:00:38.484: E/AndroidRuntime(13778): at com.tonicartos.widget.stickygridheaders.StickyGridHeadersGridView.onScroll(StickyGridHeadersGridView.java:287)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.widget.AbsListView.invokeOnItemScrollListener(AbsListView.java:1340)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.widget.AbsListView.trackMotionScroll(AbsListView.java:4989)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.widget.AbsListView.scrollIfNeeded(AbsListView.java:3126)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.widget.AbsListView.onTouchEvent(AbsListView.java:3400)
01-28 14:00:38.484: E/AndroidRuntime(13778): at com.tonicartos.widget.stickygridheaders.StickyGridHeadersGridView.onTouchEvent(StickyGridHeadersGridView.java:445)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.view.View.dispatchTouchEvent(View.java:7384)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2203)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1938)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1952)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1952)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1952)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1952)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1952)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1952)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1952)
01-28 14:00:38.484: E/AndroidRuntime(13778): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1966)
01-28 14:00:38.484: E/AndroidRuntime(13778): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1418)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.app.Activity.dispatchTouchEvent(Activity.java:2424)
01-28 14:00:38.484: E/AndroidRuntime(13778): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1914)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.view.View.dispatchPointerEvent(View.java:7564)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3883)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3778)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3483)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3540)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5419)
01-28 14:00:38.484: E/AndroidRuntime(13778): at android.

@a-thomas

That NPE occured when I was using a TextView as the parent of the item view. I added a FrameLayout as parent to fix that crash. It's a quick fix but it works ;)

@AndroidDeveloperLB

you mean putting the header as a frameLayout that has a textview ?

@a-thomas

Exactly ;)

@AndroidDeveloperLB

@a-thomas it was a long time ago. maybe that's how i've used it in the end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment