Android 未找到资源异常
我试图在我的项目中使用datepicker。但当我运行该项目时,它会抛出“ResourceNotFoundException”,当我在xml文件中拖动datepicker时,会出现下面一行Android 未找到资源异常,android,datepicker,Android,Datepicker,我试图在我的项目中使用datepicker。但当我运行该项目时,它会抛出“ResourceNotFoundException”,当我在xml文件中拖动datepicker时,会出现下面一行 The following classes could not be found: - CalendarView (Change to android.widget.CalendarView, Fix Build Path, Edit XML) - DatePicker (Change to android.
The following classes could not be found:
- CalendarView (Change to android.widget.CalendarView, Fix Build Path, Edit XML)
- DatePicker (Change to android.widget.DatePicker, Fix Build Path, Edit XML)
logcat条目如下所示:
FATAL EXCEPTION:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.dateandtimepick/com.example.dateandtimepick.MainActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x16
如何更正代码。提前谢谢
android.content.res.Resources$NotFoundException:字符串资源ID#0x16
您正试图在中设置int
值
tetview.setText()
或Toast.makeText()
,它将作为字符串资源id
所以试着像这样给int值
.setText(“+intvalue)
或Toast.makeText(context,“+intvalue,…)
我通过重新安装Android SDK解决了“资源未找到”异常。出于某种原因,在打包apk时,SDK工具没有打包资源。这是一个构建错误(静默错误),只在运行时发出喊叫。我不需要重新启动JDK或eclipse 在我看来,这是一个糟糕的导入语句…@Goddchen那么我该怎么办?您使用的是哪种api?找不到以下类:如果是这样,是否存在运行时异常发布完整堆栈跟踪,否则发布您的xml文件和api版本using@AlexChengalanapi级别17I正在处理类似的问题。事实上,是我没有注意到。我的代码是
setText('A'+i)
。花了很长时间才意识到'a'+i
实际上是对资源的引用(因为char
可以解释为int
)。所以,如果你遇到这样的问题,记得检查一下。要修复此问题,只需将其更改为setText(String.valueOf('A'+i))
。