我正在做一个测验应用程序,在不同的章节中有很多问题。当然每一章都是一个数组。
但是现在,我已经到了需要一个特定章节来从所有章节中提取所有问题和答案的地步。所以基本上它是另一个数组中的一个数组。
public void shuffleChapterRandomTest() {
shuffledPositionChapterRandomTest = new String[chapterRandomTestQuestions.length];
for (int k = 0; k < shuffledPositionChapterRandomTest.length; k++) {
shuffledPositionChapterRandomTest[k] = String.valueOf(k);
}
Collections.shuffle(Arrays.asList(shuffledPositionChapterRandomTest));
Log.i("TAG", "shuffle: " + shuffledPositionChapterRandomTest[0] + " " + shuffledPositionChapterRandomTest[1]);
}
public static String shuffledPositionChapterRandomTest[];
private String chapterRandomTestQuestions[][] = {
//This are all the chapters being called
Questions,
chapterTwoQuestions,
chapterThreeQuestions,
chapterFourQuestions,
chapterFiveQuestions,
chapterSixQuestions,
chapterSevenQuestions,
chapterEightQuestions,
chapterNineQuestions,
chapterTenQuestions,
chapterElevenQuestions,
chapterTwelveQuestions,
chapter13Questions,
chapter14Questions
};
//This is my get method
public String[] getChapterRandomTestQuestion(String a) {
return chapterRandomTestQuestions[Integer.parseInt(a)];
}
当我尝试从“问题”中提取字符串作为 TextView 的 setText 时。
private void updateQuestion() {
if (questionnumber < questionBank.getChapterRandomTestLength()) {
storeUserData.setInt(Constants.TOTAL_QUESTION,questionBank.getChapterRandomTestLength());
binding.tvCountQuestion.setText(questionnumber+1+"/"+questionBank.getChapterRandomTestLength());
它显示一个错误:
必需:Java.lang.String 找到:Java.lang.String[]
如何将问题和答案提取为字符串而不是数组。谢谢!
慕桂英4014372
相关分类