- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
问题是 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/
我正在使用 CustomMultiAutoCompleteTextView 引用 this 选择多个联系人在该代码中选择多个联系人,但我想显示在 toast 消息上选择的数字是什么。当为此单击按钮时,
我想改变我的 snackbar 的颜色 snackbarView.setBackgroundColor(ContextCompat.getColor(context, Color.RED)); 我得到
E/AndroidRuntime( 5751): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.exam
我已经用maven构建了我的项目所有构建成功并且 eclipse 属性生成也成功 但是当我在 Eclipse 4 中打开项目时,出现此错误 An internal error occurred dur
我刚刚学习了 Android 编码,这是一个简单的除法、乘法、加法和减法应用程序的源代码,该应用程序在我和我 friend 的 Android 手机上崩溃(在 Lenovo A390 和 Nexus
这是我的 .java 文件: package com.example.rohitkulkarni.readingfile; import android.os.Environment; import
因此,每当我运行我的应用程序时,它都会立即崩溃并给出以下错误: No package identifier when getting value for resource number 0x00000
我正在使用 zxing 解码二维码图像,但它总是返回 NotFoundException。在线解码器 http://zxing.org/w/decode.jspx扫描这些图像非常好,所以它应该能够在我
我注意到我的华为手机生产应用的许多崩溃报告与复数处理完全相关。其他手机没有这个问题只有华为才有。 所有复数形式都存在并且在其他设备上也能正常工作。 看来华为根本无法处理复数: android.cont
我有一个拥有超过 100.000 名用户的应用程序。但是在某些设备(~50)上我得到了一个奇怪的异常。堆栈跟踪显示,未找到可绘制对象。 这是堆栈跟踪: java.lang.RuntimeExcepti
我尝试使用 Zxing 来解码 Aztec 代码。 我使用来自 SO answer 的代码.这是其中的一部分: public static String readQRCode(String fileP
我正在创建一个应用程序,玩家可以在该应用程序中将自己的名字输入到编辑文本中。此信息被检索并通过 extras 发送到第二个 Activity 。每当我运行它时,我都会收到 Resources$NotF
我尝试构建 apk 的发布版本并在 Honor 5x (api 23) 上启动时出现错误: Caused by: android.view.InflateException: Binary XML f
我的一个应用在三星 S5(准确地说是 SM G900V)上崩溃了,但有以下异常(exception): android.content.res.Resources$NotFoundException:
我收到来自 android 市场的崩溃报告: android.content.res.Resources$NotFoundException: Resource ID #0x.... 我每周会收到大约
我有一个动态功能模块,它有自己的嵌套导航图。我还有一个动态功能模块,它只是一个 fragment 。如果您有一个带有自己导航图的动态功能模块,我知道您需要使用 包含动态标签。当我构建应用程序并将应用程
我的选项菜单中有一个麦克风按钮。当我单击它时,我希望它显示备用图像(红色麦克风)。 但是它不起作用。失败并出现 ResourcesNotFoundException。图像(png)肯定位于适当的 re
我正在循环显示近 4,000 张带有图像名称的图像。 这是我用来从可绘制文件夹获取图像的代码 for(int i=0; i
我试图扩展一个RelativeLayout对象并包含一个嵌入的SurfaceView对象,该对象使用/res/drawable文件夹中的png文件作为背景,但我在XML布局编辑器中不断收到错误。请参阅
崩溃发生在不同设备、不同 Android 版本的总用户中的 0.1%。 android.content.res.Resources$NotFoundException: at android.co
我是一名优秀的程序员,十分优秀!