Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App crashing when trying to use RecyclerView on android 5.0

I'm trying to mess with the new RecyclerView and whenever I try to run it, my app immediately crashes. It gives me NullPointerException for trying to access methods from android.support.v7.widget.RecyclerView. I've looked at other posts and saw that most people didn't have compile 'com.android.support:recyclerview-v7:+' but I tried that and it hasn't helped at all. Not really sure what to do at this point, any help would be appreciated. Here the error log: (I would post a picture but I don't have 10 rep yet)

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView$LayoutManager.onMeasure(android.support.v7.widget.RecyclerView$Recycler, android.support.v7.widget.RecyclerView$State, int, int)' on a null object reference         at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:1764)         at android.view.View.measure(View.java:17430)         at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:727)         at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:463)         at android.view.View.measure(View.java:17430)         at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)         at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)         at android.view.View.measure(View.java:17430)         at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)         at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)         at android.view.View.measure(View.java:17430)         at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)         at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)         at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)         at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)         at android.view.View.measure(View.java:17430)         at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:851)         at android.view.View.measure(View.java:17430)         at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)         at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)         at android.view.View.measure(View.java:17430)         at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)         at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)         at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)         at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)         at android.view.View.measure(View.java:17430)         at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)         at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)         at android.view.View.measure(View.java:17430)         at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)         at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)         at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)         at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)         at android.view.View.measure(View.java:17430)         at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)         at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)         at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2560)         at android.view.View.measure(View.java:17430)         at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2001)         at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1166)         at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1372)         at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1054)         at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5786)         at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)         at android.view.Choreographer.doCallbacks(Choreographer.java:580)         at android.view.Choreographer.doFrame(Choreographer.java:550)         at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)         at android.os.Handler.handleCallback(Handler.java:739)         at android.os.Handler.dispatchMessage(Handler.java:95)         at android.os.Looper.loop(Looper.java:135)         at android.app.ActivityThread.main(ActivityThread.java:5221)         at java.lang.reflect.Method.invoke(Native Method)         at java.lang.reflect.Method.invoke(Method.java:372)         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693) 
like image 648
Joe Avatar asked Dec 11 '14 06:12

Joe


People also ask

Why is app crashes in emulator Android studio?

An Android app crashes whenever there's an unexpected exit caused by an unhandled exception or signal. An app that is written using Java or Kotlin crashes if it throws an unhandled exception, represented by the Throwable class.

Is RecyclerView deprecated?

Today, suddenly Recyclerview. Viewholder became deprecated. Other, android project is no deprecated.

How do you troubleshoot the android application which is crashing frequently in Android Studio?

The easiest way to fix an app that keeps crashing on your Android smartphone is to simply force stop it and open it again. To do this, go to Settings -> Apps and select the app that keeps crashing. Tap on the app's name and then tap on 'Force stop'. Now try opening the app again and see if it works well.

What is RecyclerView LayoutManager?

A RecyclerView.LayoutManager implementation that lays out items in a grid for leanback VerticalGridView and HorizontalGridView . LinearLayoutManager. A RecyclerView.LayoutManager implementation which provides similar functionality to ListView .


1 Answers

This issue usually occurs when no LayoutManager was provided for the RecyclerView. You can do it like so:

final LinearLayoutManager layoutManager = new LinearLayoutManager(context); layoutManager.setOrientation(LinearLayoutManager.VERTICAL); recyclerView.setLayoutManager(layoutManager); 
like image 172
aga Avatar answered Sep 21 '22 12:09

aga