ListView中的资源$ NotFoundException

时间:2011-09-30 10:14:34

标签: android

我总是得到一个Resources $ NotFoundException,但我不知道为什么。请帮忙

代码:

@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = new ViewHolder();
        LayoutInflater li = (LayoutInflater)CustomAdapter.this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        if (convertView == null) {
            convertView = li.inflate(R.layout.customlistitem,null);
            holder.mTexttitle = (TextView) convertView.findViewById(R.id.item_title);
            holder.mTextrate = (TextView) convertView.findViewById(R.id.item_rate);
            convertView.setTag(holder);
        }
        else{
            holder = (ViewHolder) convertView.getTag();
        }
        holder.mTexttitle.setText(pizzen.get(position).title);
        holder.mTextrate.setText(pizzen.get(position).rate);
        //holder.mTextdate.setText(pizzen.get(position).date.toString());
        return convertView;

    }


public class ViewHolder {

    public TextView mTexttitle;
    public TextView mTextrate;
    public TextView mTextdate;
    public ImageView mImageView;

}

堆栈跟踪:

09-30 10:11:07.001: ERROR/XXX List View(1032): android.widget.ListView@43d133c0
09-30 10:11:07.021: ERROR/XXX(1032): Courser Enter: EditText
09-30 10:11:07.031: ERROR/XXX(1032): Count:1
09-30 10:11:07.031: ERROR/XXX(1032): Item[0] -->com.korn.pizzacounter.Pizza@43d16468
09-30 10:11:07.031: ERROR/XXX(1032): 1
09-30 10:11:07.101: ERROR/AndroidRuntime(1032): Uncaught handler: thread main exiting due to uncaught exception
09-30 10:11:07.121: ERROR/AndroidRuntime(1032): android.content.res.Resources$NotFoundException: String resource ID #0x2
09-30 10:11:07.121: ERROR/AndroidRuntime(1032):     at android.content.res.Resources.getText(Resources.java:200)
09-30 10:11:07.121: ERROR/AndroidRuntime(1032):     at android.widget.TextView.setText(TextView.java:2813)
09-30 10:11:07.121: ERROR/AndroidRuntime(1032):     at com.korn.pizzacounter.CustomAdapter.getView(CustomAdapter.java:44)
09-30 10:11:07.121: ERROR/AndroidRuntime(1032):     at android.widget.AbsListView.obtainView(AbsListView.java:1274)
09-30 10:11:07.121: ERROR/AndroidRuntime(1032):     at android.widget.ListView.makeAndAddView(ListView.java:1668)
09-30 10:11:07.121: ERROR/AndroidRuntime(1032):     at android.widget.ListView.fillDown(ListView.java:637)

1 个答案:

答案 0 :(得分:33)

holder.mTextrate.setText(pizzen.get(position).rate);

如果rate是int,则android认为您传递了资源ID并尝试查找资源。您需要显式地将int转换为String:String.valueOf(pizzen.get(position).rate)

rate真的是int?