NullPointerException at RecycleView

谁说胖子不能爱 提交于 2019-12-25 03:46:05

问题


i've been trying to use the TwoWay lib for a horizonal listview implemention, so i got the RecycleView lib and the TwoWay, but at both run time and the xml i receive this Exception :

09-21 01:46:52.148: E/AndroidRuntime(12471): FATAL EXCEPTION: main
09-21 01:46:52.148: E/AndroidRuntime(12471): java.lang.NullPointerException
09-21 01:46:52.148: E/AndroidRuntime(12471):    at 
com.lifemate.lmmessenger.recycleview.RecyclerView.onMeasure(RecyclerView.java:1346)
09-21 01:46:52.148: E/AndroidRuntime(12471):    at  
android.view.View.measure(View.java:12881)
09-21 01:46:52.148: E/AndroidRuntime(12471):    at   
android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:599)
09-21 01:46:52.148: E/AndroidRuntime(12471):    at 
android.widget.RelativeLayout.onMeasure(RelativeLayout.java:381)
09-21 01:46:52.148: E/AndroidRuntime(12471):    at 
android.view.View.measure(View.java:12881)

i searched alot and i found out this solution :

          bgListView.setHasFixedSize(true);

          mLayoutManager = new LinearLayoutManager(this);
          bgListView.setLayoutManager(mLayoutManager);

but then i realized that the exception happenes at creating the view before any code is compiled! does any one have any idea why is this?


回答1:


I assume by "the exception happens at creating the view" you mean you are seeing the exception in your editor. This is not a bug, rather a lack of integration with the IDE. A recycler view does not work without a layout manager. Since the code that sets the layout manager is not executed in the IDE, you see this error.

In the future, there will be better integration.




回答2:


The RecyclerView is in preview release and can contain bugs.

In particular you have to set a LayoutManager for your RecyclerView otherwise you will see an exception at Runtime. No one LayoutManager is provided by default in the current implemetation.



来源:https://stackoverflow.com/questions/25953498/nullpointerexception-at-recycleview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!