我是新手,运行该应用程序时出现以下错误。请帮助我找出问题所在。如果您在此代码中发现任何其他错误或不规范之处,请帮助我进行更正。
Process: com.example.openlab_projectayh, PID: 2881
android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:237)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2281)
at android.content.res.Resources.getLayout(Resources.java:1175)
at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
at com.example.openlab_projectayh.xinxiadpater.getView(xinxifragment.java:87)
at android.widget.AbsListView.obtainView(AbsListView.java:2405)
at android.widget.ListView.onMeasure(ListView.java:1297)
at android.view.View.measure(View.java:24530)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6828)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
at android.view.View.measure(View.java:24530)
at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1414)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.widget.ScrollView.onMeasure(ScrollView.java:452)
at android.view.View.measure(View.java:24530)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6828)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:24530)
`
这是Java代码。我写了一个片段。
public class xinxifragment extends Fragment {
private List<xinxi> nameList =new ArrayList<>();
xinxifragment(){}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.wode_scrollview, container, false);
ListView listView = view.findViewById(R.id.wode_listivew);
initxinxi();
xinxiadpater adapter = new xinxiadpater(getActivity(),R.layout.wode,nameList);
listView.setAdapter(adapter);
return view;
}
public void initxinxi(){
for(int i=0;i<2;i++){
xinxi mayijinfu = new xinxi("蚂蚁金服",R.id.dingdan);
nameList.add(mayijinfu);
xinxi shangjiafuwu = new xinxi("商家服务",R.id.faxian);
nameList.add(shangjiafuwu);
xinxi zhangdan = new xinxi("账单",R.id.dingdan);
nameList.add(zhangdan);
xinxi zongzichan = new xinxi("总资产",R.id.faxian);
nameList.add(zongzichan);
xinxi yue= new xinxi("余额",R.id.dingdan);
nameList.add(yue);
xinxi yuebao = new xinxi("余额宝",R.id.dingdan);
nameList.add(yuebao);
xinxi yinhangka = new xinxi("银行卡",R.id.dingdan);
nameList.add(yinhangka);
xinxi kefu = new xinxi("客服",R.id.dingdan);
nameList.add(kefu);
}
}
class xinxiadpater extends ArrayAdapter<xinxi> {
private Context context;
private int resourceId;
public xinxiadpater( Context context, int resourceId,List<xinxi> objects) {
super(context, resourceId, objects);
this.context = context;
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
final xinxi name =getItem(position);
View view;
ViewHolder viewHolder;
if(convertView == null){
view = LayoutInflater.from(getContext()).inflate(resourceId, parent,false);
viewHolder = new ViewHolder();
viewHolder.textView = view.findViewById(R.id.name);
viewHolder.imageView = view.findViewById(R.id.image);
viewHolder.xian = view.findViewById(R.id.xian);
view.setTag(viewHolder);
}else{
view = convertView;
viewHolder = (ViewHolder) view.getTag();
}
viewHolder.textView.setText(name.getName());
viewHolder.imageView.setImageResource(name.getImageId());
viewHolder.textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context,name.getName(),Toast.LENGTH_SHORT).show();
}
});
viewHolder.imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context,name.getName(),Toast.LENGTH_SHORT).show();
}
});
return view;
}
class ViewHolder{
TextView textView;
ImageView imageView;
View xian;
}
也许我的错误很愚蠢,但是这个项目对我很重要。