Recyclerview上的空指针异常

时间:2015-06-19 06:58:50

标签: android android-recyclerview

我正在尝试在片段中使用回收器视图,但我得到了 android.support.v7.widget.RecyclerView.onMeasure上的java.lang.NullPointerException

我还为linearlayout漫画添加了代码

下面是片段oncreateview

中的代码
    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.dummyfrag_scrollableview);
    recyclerView.setHasFixedSize(true);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
    linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    List<String> list = new ArrayList<String>();
    recyclerView.setLayoutManager(linearLayoutManager);
    for (int i = 0; i < VersionModel.data.length; i++) {
        list.add(VersionModel.data[i]);
    }
    adapter = new SimpleRecyclerAdapter(list);
    recyclerView.setAdapter(adapter);

以下是我的完整追踪

 java.lang.NullPointerException
        at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:1764)
        at android.view.View.measure(View.java:16645)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
        at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:573)
        at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:640)
        at android.view.View.measure(View.java:16645)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
        at android.support.v7.internal.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:124)
        at android.view.View.measure(View.java:16645)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
        at android.view.View.measure(View.java:16645)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
        at android.view.View.measure(View.java:16645)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
        at android.view.View.measure(View.java:16645)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
        at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2295)
        at android.view.View.measure(View.java:16645)
        at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1916)
        at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1113)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1295)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5633)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
        at android.view.Choreographer.doCallbacks(Choreographer.java:574)
        at android.view.Choreographer.doFrame(Choreographer.java:544)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
        at android.os.Handler.handleCallback(Handler.java:743)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5196)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
        at dalvik.system.NativeStart.main(Native Method)

0 个答案:

没有答案