我从许多设备中获得以下异常,例如 Sumsung GT-I8190N Android:4.1.2, Sumsung GT-I8552 Android:4.1.2, Sumsung GT-I9300安卓:4.3, Sumsung GT-S5830 Android:2.2.1, Sumsung GT-S7262 Android:4.1.2, LGE LG-P768 Android:4.0.4, 华为G610-U20 Android:4.2.1, 华为G730-U10 Android:4.2.2, 等
java.lang.NullPointerException
at android.support.v7.widget.RecyclerView.dispatchLayout(SourceFile:2626)
at android.support.v7.widget.RecyclerView.onLayout(SourceFile:3011)
at android.view.View.layout(View.java:13856)
at android.view.ViewGroup.layout(ViewGroup.java:4424)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:948)
at android.view.View.layout(View.java:13856)
at android.view.ViewGroup.layout(ViewGroup.java:4424)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:13856)
at android.view.ViewGroup.layout(ViewGroup.java:4424)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:948)
at android.view.View.layout(View.java:13856)
at android.view.ViewGroup.layout(ViewGroup.java:4424)
at android.support.v4.widget.DrawerLayout.onLayout(SourceFile:907)
at android.view.View.layout(View.java:13856)
at android.view.ViewGroup.layout(ViewGroup.java:4424)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:13856)
at android.view.ViewGroup.layout(ViewGroup.java:4424)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1655)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1513)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1426)
at android.view.View.layout(View.java:13856)
at android.view.ViewGroup.layout(ViewGroup.java:4424)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:13856)
at android.view.ViewGroup.layout(ViewGroup.java:4424)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1655)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1513)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1426)
at android.view.View.layout(View.java:13856)
at android.view.ViewGroup.layout(ViewGroup.java:4424)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:13856)
at android.view.ViewGroup.layout(ViewGroup.java:4424)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1992)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1813)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1113)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4481)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
at android.view.Choreographer.doCallbacks(Choreographer.java:555)
at android.view.Choreographer.doFrame(Choreographer.java:525)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4856)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
at dalvik.system.NativeStart.main(Native Method)
支持库版本也是compile 'com.android.support:support-v4:22.2.1'
。顺便说一下,我检查过非findViewById
函数返回null并搜索了很多,以便在互联网上找到相同的错误,但没有找到结果。
知道如何解决这个问题吗?
答案 0 :(得分:0)
您好我猜这种错误通常会在您错过将setLayoutManager应用到您的回收站视图时触发。确保将布局管理器应用于您的收视方式视图,请参阅以下示例:
mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
LinearLayoutManager layoutManager = new LinearLayoutManager(context);
mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView.setAdapter(new CustomAdapter());