Groupie: NullPointerEx in example app

Created on 18 Jan 2017  Â·  5Comments  Â·  Source: lisawray/groupie

Hi @lisawray
I tried today for the first time the example app and it keeps crashing on the newly added onClickListener code with this stacktrace:

java.lang.NullPointerException: Attempt to invoke interface method 'void com.genius.groupie.OnItemClickListener.onItemClick(com.genius.groupie.Item, android.view.View)' on a null object reference at com.genius.groupie.ViewHolder$1.onClick(ViewHolder.java:22)at android.view.View.performClick(View.java:5637)at android.view.View$PerformClick.run(View.java:22429)at android.os.Handler.handleCallback(Handler.java:751)at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

Debugging show me that in this piece of code:
if (getAdapterPosition() != NO_POSITION) { onItemClickListener.onItemClick(getItem(), v); }
onItemClickListener it's always null. At first, I thoughts it was an error in the ViewHolder bind method but I'm not quite sure now.
Before writing this, I tried to find a duplicate issue in the list and it seems not present.Anyway, I could be wrong so...sorry, just in case :)

Most helpful comment

@lisawray I can confirm actually this solved the problem. It's now working perfectly. @lkishor are u gonna submit a PR for this?

All 5 comments

I'll check it out this evening!

On Wed, Jan 18, 2017 at 9:22 AM, spectrumIG notifications@github.com
wrote:

Hi @lisawray https://github.com/lisawray
I tried today for the first time the example app and it keeps crashing on
the newly added onClickListener code with this stacktrace:

java.lang.NullPointerException: Attempt to invoke interface method 'void
com.genius.groupie.OnItemClickListener.onItemClick(com.genius.groupie.Item,
android.view.View)' on a null object reference at
com.genius.groupie.ViewHolder$1.onClick(ViewHolder.java:22)at
android.view.View.performClick(View.java:5637)at android.view.View$
PerformClick.run(View.java:22429)at android.os.Handler.
handleCallback(Handler.java:751)at android.os.Handler.
dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.
java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(
ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

Debugging show me that in this piece of code:
if (getAdapterPosition() != NO_POSITION) { onItemClickListener.onItemClick(getItem(),
v); }
onItemClickListener it's always null. At first, I thoughts it was an error
in the ViewHolder bind method but I'm not quite sure now.
Before writing this, I tried to find a duplicate issue in the list and it
seems not present.Anyway, I could be wrong so...sorry, just in case :)

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Genius/groupie/issues/71, or mute the thread
https://github.com/notifications/unsubscribe-auth/ABZesbh988pnp6p2PLsHQZcoCfbTZgf9ks5rTiAtgaJpZM4Lm8B4
.

Hi @lisawray
you missed setting the onItemClickListener reference in bind() of ViewHolder
i.e within the if block
if (onItemClickListener != null && item.isClickable()) { binding.getRoot().setOnClickListener(onClickListener); this.onItemClickListener = onItemClickListener; //Currently missing }

@lisawray I can confirm actually this solved the problem. It's now working perfectly. @lkishor are u gonna submit a PR for this?

Thank you for your patience. I've just worked through transferring the library on github with the guys at Genius and will be publishing a new release ASAP under a different package name!

We're live with this fix now on jcenter at com.xwray:groupie:1.0.0 :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ovitrif picture ovitrif  Â·  5Comments

alvin-nt picture alvin-nt  Â·  3Comments

FabianTerhorst picture FabianTerhorst  Â·  6Comments

amervelic picture amervelic  Â·  3Comments

vahids28 picture vahids28  Â·  4Comments