Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
315 views
in Technique[技术] by (71.8m points)

java - Deleting item in Recyclerview in Fragment leads to NPE of another Activity

I am currently developing an app that has a function like a simple news feed which displays news etc. In it, i have a fragment which contains a Recyclerview populated by Firebase' ValueEventListener.

When a user clicks an item, it opens an Activity (Detail Activity) containing the additional details of the clicked Recyclerview item. The contents of the Activity is populated using Value Event Listener that listens to a specific location in the database(items in the recylcerview).

The problem is, sometimes when i delete an item in the recyclerview, an NPE will be triggered by the DetailActivty's ValueEventListener mainly due to binding items in some views.

My suspicion is that after i delete an item in the recyclerview, the ValueEventListener in the DetailActivity still listens to the item's firebase reference, hence causing NPE.

I could use a database reference if it's only fetching data, but i also want to listen to data changes that's why i used a ValueEventListener.

I'd like to know what seems to be the problem and possible fix in this question.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...