0
我有一個問題,調用我的數組........ 我想做一個類似遊戲的hang子手...... 我做每個類別的字符串數組....獲取每個類別選擇的隨機數組
這裏是我的一些代碼game.java
public static final String KEY_CATEGORY = "package.name.category";
public static int CATEGORY_CITY = 0;
public static int CATEGORY_ANIMAL = 1;
public static int CATEGORY_FRUIT = 2;
public static int CATEGORY_PLANT = 3;
private void setWordByCategory() {
// TODO Auto-generated method stub
cat = getIntent().getIntExtra(KEY_CATEGORY,CATEGORY_CITY);
mysteryWord = getWord (cat);
private String getWord(int cat) {
if (cat == CATEGORY_CITY) {
String[] array = getResources().getStringArray(R.array.cityarray);
String randomStr = array[new Random().nextInt(array.length)];
} else if (cat == CATEGORY_ANIMAL) {
String[] array = getResources().getStringArray(R.array.animalarray);
String randomStr = array[new Random().nextInt(array.length)];
} else if (cat == CATEGORY_FRUIT) {
String[] array = getResources().getStringArray(R.array.fruitarray);
String randomStr = array[new Random().nextInt(array.length)];
} else if (cat == CATEGORY_PLANT) {
String[] array = getResources().getStringArray(R.array.plantarray);
String randomStr = array[new Random().nextInt(array.length)];
}
// TODO Auto-generated method stub
return mysteryWord;
}
什麼是錯我的代碼? 它說「RandomStr的價值不被使用」... 它顯示沒有錯誤..但是當我嘗試運行它時,它只是強制關閉後選擇一個類別... 不能去game.java
@ user2336315那麼如何解決它..?對不起,我只是在Java新...你能幫我先生..? –
顯示你的崩潰日誌? –