Cause for NullPointerException android.support.v7.widget.RecyclerView.onMeasure

后端 未结 4 1200
北海茫月
北海茫月 2020-12-15 17:44

I am getting following Exception

01-27 11:15:15.756  18348-18348/com.example.pnimje.newswipelistview E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.Nu         


        
4条回答
  •  盖世英雄少女心
    2020-12-15 18:10

    These kinds of errors usually originate in not setting the RecyclerView's layout manager. Bein' in a hurry myself I forgot to set one which ended in the following error:

    java.lang.NullPointerException
            at android.support.v7.widget.RecyclerView.onInterceptTouchEvent(RecyclerView.java:1636)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1820)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2177)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1878)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2177)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1878)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2177)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1878)
    

    The following line should resolve it:

    mRecyclerView.setLayoutManager(new LinearLayoutManager((Activity)this));
    

提交回复
热议问题