gpt4 book ai didi

android - Android 中的资源$NotFoundException

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:20:35 25 4
gpt4 key购买 nike

问题是 tv2.settext() 中的 Resources$NotFoundException,我不知道为什么我在披萨标题和计数中有一个 TreeMap。请帮忙!

调用:

for (Pizza pizza : list) {

if(map.containsKey(pizza.title))
{

int i = map.get(pizza.title);
map.remove(pizza.title);

map.put(pizza.title, i++);
}
else
{
map.put(pizza.title, 1);
}
}

披萨:

public class Pizza implements Comparable<String> {

public String title;
public int rate;
public String date;
public Bitmap picture;
public int id;
@Override
public int compareTo(String another) {
// TODO Auto-generated method stub
return this.title.compareTo(another);
}

}

错误代码:

for (Entry<String, Integer> entry : map.entrySet()) {

tv.setText(entry.getKey());
tv2.setText((Integer)entry.getValue()); //Error occures here

tv.setGravity(Gravity.LEFT);
tv2.setGravity(Gravity.RIGHT);

TableRow tr1 = new TableRow(this);
tr1.addView(tv);
tr1.addView(tv2);
tl.addView(tr1, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
}
}

错误:

10-04 09:04:40.475: ERROR/AndroidRuntime(954): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x1

最佳答案

tv2.setText((Integer)entry.getValue()); 更改为

tv2.setText(entry.getValue().toString());

这样做

 TableRow tr1 = new TableRow(this);

for (Entry<String, Integer> entry : map.entrySet()) {

tv.setText(entry.getKey());
tv2.setText((Integer)entry.getValue()); //Error occures here

tv.setGravity(Gravity.LEFT);
tv2.setGravity(Gravity.RIGHT);

tr1.addView(tv);
tr1.addView(tv2);
tl.addView(tr1, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
}
}

关于android - Android 中的资源$NotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7645668/

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