资源未找到异常

Neh*_*gla 2 android datepicker

我想在我的项目中使用datepicker.但是一旦我运行该项目,它就会抛出"资源未找到异常",当我在xml文件中拖动datepicker时会出现以下行

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)
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

我该如何纠正代码.提前致谢.

Pra*_*ani 11

android.content.res.Resources $ NotFoundException:字符串资源ID#0x16

您正在尝试设置int

tetview.setText()或者Toast.makeText(),它将作为字符串资源ID.

所以试着像这样给出int值

.setText(""+intvalue) 要么 Toast.makeText(context,""+intvalue,..)

  • 我正在处理类似的问题.实际上,这是我缺乏关注.我的代码是`setText('A'+ i)`.花了很长时间才意识到''A'+ i`实际上是对Resource的引用(因为`char`可能被解释为`int`).所以,如果你遇到这样的问题,请记得检查一下.要修复,只需将其更改为`setText(String.valueOf('A'+ i))`. (2认同)