gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 12:59:09 25 4
gpt4 key购买 nike

当我运行我的应用程序时,我从标题中得到了异常。它的作用是它有一个带有 Hangman 游戏单词的 .txt 文件,我认为访问该文件时会引发异常。我的文件 cuvinte.txt 位于/assets/。这是我的代码(我跳过了 layout/xml 部分,效果很好):

public void onCreate() {
// all the onCreate() 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() 函数在新游戏按钮被按下时和 Activity 开始时在 onCreate() 函数中被调用。

最佳答案

(只是假设,Exception stacktrace的信息较少)

我认为,这一行 incercari.setText(valIncercari); throws Exception因为 valIncercariint

应该是这样的,

incercari.setText(valIncercari+"");

或者

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

关于Android:android.content.res.Resources$NotFoundException:字符串资源 ID #0x5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11189545/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com