SLaks 2013-05-23 03:26 采纳率: 0%
浏览 2247
已采纳

线程和 NotFound resource exception

我现在遇见一个问题是 NotFound resource exception。我确信 resource-id和我设置的是一样的,但总是不对。第一行"findViewById( R.id.editText1 )" 可以很好的运行,可以在editText1中看到 "start!" 标签。
但是第二行在线程中,有错误信息:09-29 00:17:45.103: E/AndroidRuntime(347): android.content.res.Resources$NotFoundException: String resource ID #0x0

如何解决这个问题呢?

EditText editText = ( EditText ) findViewById( R.id.editText1 );
editText.setText( "start!" );
final Handler handler = new Handler();
Runnable runnable = new Runnable() {
    @Override
    public void run() {
        for (int i = 0; i <= 10; i++) {
            final int value = i;
            try {
                Thread.sleep( 1000 );
             } catch ( InterruptedException e ) {
                e.printStackTrace();
             }
            handler.post( new Runnable() {
               @Override
               public void run() {
                   EditText editText = ( EditText ) findViewById( R.id.editText1 );
                   editText.setText( value );
               }
           } );
        }
    }
 };
 Thread thread = new Thread( runnable );
thread.start();
  • 写回答

3条回答

  • 问答小助手 2013-05-23 09:18
    关注

    value 是一个整数值。传递一个整数值到 setText 方法,你可以通过 resource ID 从 strings.xml 文件中找到一个 String。如果你想显示一个数字,你需要把它解析成:String: Integer.toString(value)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料