gpt4 book ai didi

java - Android ButterKnife NullPointer 在 CustomAdapter 中绑定(bind)

转载 作者:行者123 更新时间:2023-12-01 18:00:54 25 4
gpt4 key购买 nike

我尝试在 My CustomAdapter 类中绑定(bind)布局组件,我在 Holder 构造函数上绑定(bind)了 ButterKnife,并在 View 组件中绑定(bind)了 BindView,如下所示:

public static class Holder
{

public Holder(View view)
{
ButterKnife.bind(this,view);
}

@BindView(R.id.txtName)
TextView tvName;

@BindView(R.id.txtGroup)
TextView tvGroup;

@BindView(R.id.imageProfile)
ImageView img;
}

这是 getView 方法:

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
Holder holder=new Holder(convertView);
View rowView;
rowView = inflater.inflate(R.layout.contact_list, null);

//holder.tvName=(TextView)rowView.findViewById(R.id.txtName);
holder.tvName.setText(result.get(position));
//holder.img=(ImageView) rowView.findViewById(R.id.imageProfile);
holder.img.setImageBitmap(imageId.get(position));
//holder.tvGroup=(TextView)rowView.findViewById(R.id.txtGroup);
holder.tvGroup.setText(listGroup.get(position));
rowView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(context, "You Clicked "+result.get(position), Toast.LENGTH_LONG).show();
}
});
return rowView;
}

但是当我运行它时,它触发 NullPointerException,这就是消息:

FATAL EXCEPTION: main
Process: com.project.echo.contactmanagement, PID: 2861
java.lang.RuntimeException: Unable to bind views for com.project.echo.contactmanagement.mainscreen.CustomAdapter$Holder
at butterknife.ButterKnife.bind(ButterKnife.java:189)
at butterknife.ButterKnife.bind(ButterKnife.java:167)
at com.project.echo.contactmanagement.mainscreen.CustomAdapter$Holder.<init>(CustomAdapter.java:61)
at com.project.echo.contactmanagement.mainscreen.CustomAdapter.getView(CustomAdapter.java:76)
at android.widget.AbsListView.obtainView(AbsListView.java:2263)
at android.widget.ListView.makeAndAddView(ListView.java:1790)
at android.widget.ListView.fillDown(ListView.java:691)
at android.widget.ListView.fillFromTop(ListView.java:752)
at android.widget.ListView.layoutChildren(ListView.java:1630)
at android.widget.AbsListView.onLayout(AbsListView.java:2091)
at android.view.View.layout(View.java:14852)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055)
at android.view.View.layout(View.java:14852)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:14852)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.support.v7.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:437)
at android.view.View.layout(View.java:14852)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:14852)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
at android.view.View.layout(View.java:14852)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:14852)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1994)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1751)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1007)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5677)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:544)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5021)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:827)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:643)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at butterknife.internal.Finder$1.findView(Finder.java:12)
at butterknife.internal.Finder.findOptionalView(Finder.java:64)
at butterknife.internal.Finder.findRequiredView(Finder.java:48)
at com.project.echo.contactmanagement.mainscreen.CustomAdapter$Holder$$ViewBinder.bind(CustomAdapter$Holder$$ViewBinder.java:17)
at com.project.echo.contactmanagement.mainscreen.CustomAdapter$Holder$$ViewBinder.bind(CustomAdapter$Holder$$ViewBinder.java:12)
at butterknife.ButterKnife.bind(ButterKnife.java:187)
at butterknife.ButterKnife.bind(ButterKnife.java:167) 
at com.project.echo.contactmanagement.mainscreen.CustomAdapter$Holder.<init>(CustomAdapter.java:61) 
at com.project.echo.contactmanagement.mainscreen.CustomAdapter.getView(CustomAdapter.java:76) 
at android.widget.AbsListView.obtainView(AbsListView.java:2263) 
at android.widget.ListView.makeAndAddView(ListView.java:1790) 
at android.widget.ListView.fillDown(ListView.java:691) 
at android.widget.ListView.fillFromTop(ListView.java:752) 
at android.widget.ListView.layoutChildren(ListView.java:1630) 
at android.widget.AbsListView.onLayout(AbsListView.java:2091) 
at android.view.View.layout(View.java:14852) 
at android.view.ViewGroup.layout(ViewGroup.java:4631) 
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055) 
at android.view.View.layout(View.java:14852) 
at android.view.ViewGroup.layout(ViewGroup.java:4631) 
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) 
at android.widget.FrameLayout.onLayout(FrameLayout.java:388) 
at android.view.View.layout(View.java:14852) 
at android.view.ViewGroup.layout(ViewGroup.java:4631) 
at android.support.v7.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:437) 
at android.view.View.layout(View.java:14852) 
at android.view.ViewGroup.layout(ViewGroup.java:4631) 
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) 
at android.widget.FrameLayout.onLayout(FrameLayout.java:388) 
at android.view.View.layout(View.java:14852) 
at android.view.ViewGroup.layout(ViewGroup.java:4631) 
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671) 
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525) 
at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) 
at android.view.View.layout(View.java:14852) 
at android.view.ViewGroup.layout(ViewGroup.java:4631) 
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) 
at android.widget.FrameLayout.onLayout(FrameLayout.java:388) 
at android.view.View.layout(View.java:14852) 
at android.view.ViewGroup.layout(ViewGroup.java:4631) 
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1994) 
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1751) 
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1007) 
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5677) 
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761) 
at android.view.Choreographer.doCallbacks(Choreographer.java:574) 
at android.view.Choreographer.doFrame(Choreographer.java:544) 
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747) 
at android.os.Handler.handleCallback(Handler.java:733) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5021) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:827) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:643) 
at dalvik.system.NativeStart.main(Native Method) 

请问有人可以帮我解决这个问题吗?

最佳答案

ButterKnife.bind(this,convertView);

关于java - Android ButterKnife NullPointer 在 CustomAdapter 中绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41054047/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com