Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android NullpointerException覆盖arrayadapter中的getview_Android - Fatal编程技术网

Android NullpointerException覆盖arrayadapter中的getview

Android NullpointerException覆盖arrayadapter中的getview,android,Android,我正试图覆盖getview方法,如下所示: public class MyArrayAdapter extends ArrayAdapter { private final Context context; private final ArrayList<DataList> values; private final LayoutInflater li = LayoutInflater.from(this.getContext()); public MyArrayA

我正试图覆盖getview方法,如下所示:

public class MyArrayAdapter extends ArrayAdapter {
private final Context context;
  private final ArrayList<DataList> values;
  private final  LayoutInflater li = LayoutInflater.from(this.getContext());


  public MyArrayAdapter(Context context, int    textViewResourceId,ArrayList<DataList> values) {
    super(context,textViewResourceId, values);
    this.context = context;
    this.values = values;
  }

  @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      ViewHolder holder;

        if(convertView==null){
            convertView=li.inflate(R.layout.simplerow,parent,false);
            holder=new ViewHolder();
            holder.text=(TextView)   convertView.findViewById(R.layout.simplerow);
            convertView.setTag(holder);
        }else{
            Log.d("a","entre else");
            holder=(ViewHolder)convertView.getTag();
       }
        DataList b=values.get(1);
        String c=b.toString();
        holder.text.setText(values.get(position).toString());
        try {

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return convertView;
    }

  static class ViewHolder {
      TextView text;
    }
公共类MyArrayAdapter扩展了ArrayAdapter{
私人最终语境;
私有最终ArrayList值;
private final LayoutInflater li=LayoutInflater.from(this.getContext());
公共MyArrayAdapter(上下文上下文、int textViewResourceId、ArrayList值){
super(上下文、textViewResourceId、值);
this.context=上下文;
这个值=值;
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
视窗座;
if(convertView==null){
convertView=li.inflate(R.layout.simplerow,父级,false);
holder=新的ViewHolder();
holder.text=(TextView)convertView.findViewById(R.layout.simplerow);
convertView.setTag(支架);
}否则{
日志d(“a”、“entre else”);
holder=(ViewHolder)convertView.getTag();
}
数据列表b=值。获取(1);
字符串c=b.toString();
holder.text.setText(values.get(position.toString());
试一试{
}捕获(例外e){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
返回视图;
}
静态类视窗夹{
文本查看文本;
}

每次我到达
holder.text.setText(values.get(position.toString())
我收到
空指针异常
错误。value是DataList类型的
数组列表
,DataList是返回两个字符串的我的类。我知道value不是空的。

原因是
holder。text
抛出空指针异常是因为您使用了错误的id:

convertView.findViewById(R.layout.simplerow);
因此
findViewById()
返回
null
。请尝试以下操作:

convertView.findViewById(R.id.textView); // I made up a name, but notice the difference?

XD非常感谢这让我疯狂LOL真的很好其他人检查你的代码因为你跳过了这样的事情。非常感谢!!!!!不麻烦,有时我们只是需要一双额外的眼睛。