После многих уроков по RecyclerViews я продолжаю аварийно завершать работу моего приложения в этой строке:
View view = inflater.inflate(R.layout.layout_listitem, parent, false);
Что, вероятно, вызвано тем, что объект inflater имеет значение null, поскольку контекст имеет значение null:
LayoutInflater inflater = LayoutInflater.from(context);
Однако я не понимаю, почему значение NULL, если я передаю контекст в конструкторе RecyclerViewAdapter:
public RecycleViewAdapter(Context context) {
this.context = context;
}
из моего фрагмента активности:
View view = inflater.inflate(R.layout.fragment_home, container, false);
recyclerView = (RecyclerView) view.findViewById(R.id.matches);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
recyclerView.setAdapter(new RecycleViewAdapter(getActivity()));
return view;
И я попробовал getContext (), getActivity (), я даже переопределил метод onAttach, чтобы получить оттуда контекст, и все равно вылетал. Я новичок в использовании фрагментов, поэтому я не знаю, что я делаю, просто использую решения, которые люди пробовали на форумах.
Logcat:
09-07 09:48:14.433 7594-7594/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: maginate.net.thebestrapper, PID: 7594
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:722)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at maginate.net.thebestrapper.RecycleViewAdapter.onCreateViewHolder(RecycleViewAdapter.java:40)
at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6685)
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5869)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5752)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5748)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2232)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1559)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1519)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:614)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3812)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3529)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:4082)
at android.view.View.layout(View.java:16916)
at android.view.ViewGroup.layout(ViewGroup.java:5405)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:16916)
at android.view.ViewGroup.layout(ViewGroup.java:5405)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:16916)
at android.view.ViewGroup.layout(ViewGroup.java:5405)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1702)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1556)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1465)
at android.view.View.layout(View.java:16916)
at android.view.ViewGroup.layout(ViewGroup.java:5405)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:16916)
at android.view.ViewGroup.layout(ViewGroup.java:5405)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1702)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1556)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1465)
at android.view.View.layout(View.java:16916)
at android.view.ViewGroup.layout(ViewGroup.java:5405)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:16916)
at android.view.ViewGroup.layout(ViewGroup.java:5405)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1702)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1556)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1465)
at android.view.View.layout(View.java:16916)
at android.view.ViewGroup.layout(ViewGroup.java:5405)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:16916)
at android.view.ViewGroup.layout(ViewGroup.java:5405)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2413)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2122)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1264)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6942)
at