安卓:android.content.res.Resources $ NotFoundException:字符串资源ID#0x5的 [英] Android: android.content.res.Resources$NotFoundException: String resource ID #0x5

查看:142
本文介绍了安卓:android.content.res.Resources $ NotFoundException:字符串资源ID#0x5的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到的异常从标题的时候我跑我的应用程序。它所做的是它有一个.txt文件的话了刽子手的游戏,我想访问该文件时抛出异常。我的文件,cuvinte.txt位于成/资产/。这是我的code(我跳过了布局/ XML的一部分,它工作正常):

I get the exception from the title when I run my app. What it does is it has a .txt file with words for a Hangman game and I think the exception is thrown when accessing the file. My file, cuvinte.txt is located into /assets/. Here is my code (i skipped the layout/xml part, which works fine):

// onCreate() with all the stuff, then this:
   try {
            AssetManager am = this.getAssets();
            InputStream is = am.open("cuvinte.txt");
            InputStreamReader inputStreamReader = new InputStreamReader(is);
            BufferedReader b = new BufferedReader(inputStreamReader);
            String rand;
            while((rand=b.readLine())!=null){
                cuvinte.add(rand);
            }
        } catch (IOException e) {
            Toast.makeText(this, "No words file", Toast.LENGTH_LONG).show();
            e.printStackTrace();
        }

        newGame(newG);
    }

    public void newGame(View view){
        Random rand = new Random();
        String stringCuvant = cuvinte.get(rand.nextInt(cuvinte.size()));
        cuvant.setText("");
        System.out.println(stringCuvant);
        for(int i = 0; i< stringCuvant.length(); i++){
            cuvant.append("_ ");
        }
        incercari.setText(valIncercari);
    }

函数newGame()被调用时,双方新的游戏按钮pressed,并在活动的开始,在所述的onCreate()函数。

The function newGame() is called both when the new game button is pressed and at the beginning of the activity, in the onCreate() function.

推荐答案

(只是假设,异常堆栈跟踪较少的信息)

(Just assumption, less info of Exception stacktrace)

我想,这条线, incercari.setText(valIncercari); 抛出异常 因为 valIncercari INT

I think, this line, incercari.setText(valIncercari); throws Exception because valIncercari is int

所以,它应该是,

incercari.setText(valIncercari+"");

incercari.setText(Integer.toString(valIncercari));

这篇关于安卓:android.content.res.Resources $ NotFoundException:字符串资源ID#0x5的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆