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
because you have not set LinearLayoutManager to RecyclerView.
for example:
mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
LinearLayoutManager layoutManager = new LinearLayoutManager(context);
mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView.setAdapter(new CustomAdapter());
You need to verify that what you are sending to the adapter is not an empty List<Type>
. I recommend you to either create the RecyclerView
by code and add it later when you have the information, or to put an empty NULL
object before passing it to the constructor of the adapter.
Antón response is good but can be confusing in beginners like me, talves this serves to clarify some doubts.
RecyclerView rv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_buscar);
rv = (RecyclerView) findViewById(R.id.RecViewTest);
LinearLayoutManager llm = new LinearLayoutManager(this);
rv.setLayoutManager(llm);
}
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));