Final Edit: This has been solved. I carelessly forgot to account for the XML made in challenge 8.1, as Jinisha and Nitrodon pointed out. Thanks everyone for the help. Happy Learning
I’m running into a weird error. I’m on page 199, where we are updating the ImageView so that the handcuffs are only shown on crimes that have been solved. At first I did everything the book asked, such as change the image ID to crime_solved, added the mSolvedImageView member to CrimeHolder, then initialized the ImageView in the CrimeHolder constructor. Then after running i into errors I realized, thanks to a post made on this forum, that crime_solved has been used as an ID in chapter 7. So like the forum post said, I changed the ID once again to solvedImageView to fix the clashing IDs. But for some reason, the mSolvedImageView variable wont initialize in the CrimeHolder constructor even after giving it a unique ID. So the NullPointerException occurs in the bind method, when I attempt to mSolvedViewImage.setVisibility(crime.isSolved() ? View.VISIBLE : View.GONE). When I run the debugger it just stays null, despite mTitleTextView and mDateTextView being initialized just fine. I don’t understand why. Please help. Here’s a part of my logcat:
2019-01-09 15:09:40.265 13299-13299/com.bignerdranch.android.criminalintent E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.bignerdranch.android.criminalintent, PID: 13299
java.lang.NullPointerException: Attempt to invoke virtual method ‘void android.widget.ImageView.setVisibility(int)’ on a null object reference
at com.bignerdranch.android.criminalintent.CrimeListFragment$CrimeHolder.bind(CrimeListFragment.java:62)
at com.bignerdranch.android.criminalintent.CrimeListFragment$SeriousCrimeHolder.bind(CrimeListFragment.java:84)
at com.bignerdranch.android.criminalintent.CrimeListFragment$CrimeAdapter.onBindViewHolder(CrimeListFragment.java:121)
at com.bignerdranch.android.criminalintent.CrimeListFragment$CrimeAdapter.onBindViewHolder(CrimeListFragment.java:96)
at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6781)
at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6823)
at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5752)
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6019)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5858)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5854)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2230)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1557)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1517)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:612)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3924)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3641)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:4194)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
Edit: As requested by the two comments below, here’s part of my CrimeListFragment.java. I also deleted some of the seemingly irrrelevant error logcat info above. I can only post one image since I’m a new user, unfortunately. I hope this part is relevant.