Android onBindViewHolder找不到视图

Android onBindViewHolder找不到视图,android,android-recyclerview,Android,Android Recyclerview,我正在recyclerview适配器中膨胀布局xml。但我每次都会遇到一个NPE,似乎无法找到问题的根源 这是我的日志: E/AndroidRuntime:致命异常:主 java.lang.NullPointerException 位于com.softtech.stevekamau.buyathome.adapter.RecomGridAdapter.onBindViewHolder(RecomGridAdapter.java:159) 位于com.softtech.stevekamau.bu

我正在
recyclerview
适配器中膨胀布局xml。但我每次都会遇到一个NPE,似乎无法找到问题的根源

这是我的日志:

E/AndroidRuntime:致命异常:主
java.lang.NullPointerException
位于com.softtech.stevekamau.buyathome.adapter.RecomGridAdapter.onBindViewHolder(RecomGridAdapter.java:159)
位于com.softtech.stevekamau.buyathome.adapter.RecomGridAdapter.onBindViewHolder(RecomGridAdapter.java:120)
位于android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:5217)
位于android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:5250)
位于android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4487)
位于android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4363)
位于android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1961)
位于android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1370)
位于android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1333)
位于android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:562)
位于android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2900)
位于android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3071)
在android.view.view.layout(view.java:13754)
位于android.view.ViewGroup.layout(ViewGroup.java:4362)

….
网格单元格.xml中文本的ID是标题和金额,请尝试使用其中一个而不是名称。像这样的

mTextView = (TextView) v.findViewById(R.id.title);

grid_cell.xml中文本的ID是标题和数量,请尝试使用其中一个而不是名称。像这样的

mTextView = (TextView) v.findViewById(R.id.title);

问题是
TextView=(TextView)v.findViewById(R.id.name);返回nullTextView
。有两种解决方案:使用
id=“name”
添加
textView
,或者您可以使用
AnyTextView TextView=(AnyTextView)v.findViewById(R.id.title)
问题在于
textview=(textview)v.findViewById(R.id.name),而不是初始化
textview

;返回nullTextView
。有两种解决方案:使用
id=“name”
添加
textView
,或者您可以使用
AnyTextView TextView=(AnyTextView)v.findViewById(R.id.title)
代替您初始化的
文本视图

mTextView
为空,因为在grid\u cell.xml中,您没有ID为
名称
的视图。尝试将分配更改为:

mTextView = (TextView) v.findViewById(R.id.title);
当然,假设“标题”是您想要得到的视图

[编辑] 抱歉,米格尔比我先到了!
[/edit]

mTextView
为空,因为在grid\u cell.xml中没有ID为
name
的视图。尝试将分配更改为:

mTextView = (TextView) v.findViewById(R.id.title);
当然,假设“标题”是您想要得到的视图

[编辑] 抱歉,米格尔比我先到了!
[/edit]

在xml文件中,您没有任何带有“name”id的
TextView
!!如何在
findViewById
中使用
R.id.name
?您必须更改您的
ViewHolder
类别:

 mTextView = (TextView) v.findViewById(R.id.title);


在xml文件中,您没有任何id为“name”的
TextView
!!如何在
findViewById
中使用
R.id.name
?您必须更改您的
ViewHolder
类别:

 mTextView = (TextView) v.findViewById(R.id.title);

可能的重复可能的重复