Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Guy BridgeAndroid Development Techdegree Graduate 24,991 Points
Getting NPE now that I have created the RecyclerAdapter class
I have just completed the steps in this video where we create the RecyclerAdapter class. The exception is:
FATAL EXCEPTION: main Process: au.com.wsit.smellslikebakin, PID: 6420 java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageResource(int)' on a null object reference at au.com.wsit.smellslikebakin.RecyclerAdapter$ListViewHolder.bindView(RecyclerAdapter.java:59) at au.com.wsit.smellslikebakin.RecyclerAdapter.onBindViewHolder(RecyclerAdapter.java:31) at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:5453)
Seth Kroger56,412 Points
In the two layout files that you choose from, grid_item.xml and list_item.xml, the ImageViews have different id names. Only one id is used in RecyclerAdapter. You need to have the same id name in both layouts for it to work.
Cindy LeaCourses Plus Student 6,497 Points
Please link your code. I wish everyone wouldnt just post errors & expect us to figure it out. Its much efficient if we see the code.