zu randomisieren Gruß peeps, brauchen Hilfe zu diesem Fehler. googeln, aber das Problem nicht lösen. Ich habe Bemerkungen gemacht, in welchen Zeilen die Fehler auftreten.Fehler beim Versuch, einige Fragen in Android App
Mitteilung Code unten hat 2 verschiedenen Java-Klasse
[IMG = "Screenshot"] http://i.imgur.com/XYFHZOz.png[/IMG]
public class QuestionAndAnswer {
public List<String> allAnswers; // distractors plus real answer
public String answer;
public String question;
public String selectedAnswer;
public int selectedId = -1;
public QuestionAndAnswer(String question, String answer, List<String> distractors) {
this.question = question;
this.answer = answer;
allAnswers = new ArrayList<String>(distractors);
// Add real answer to false answers and shuffle them around
allAnswers.add(answer);
Collection.shuffle(allAnswers); //error on this line
}
public boolean isCorrect() {
return answer.equals(selectedAnswer);
}
}
public class UjiSalah extends Activity {
RadioGroup rg;
int currentQuestion = 0;
TextView tv;
List<QuestionAndAnswer> quiz = new ArrayList<QuestionAndAnswer>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.uji_salah);
tv = (TextView) findViewById(R.id.tvque);
rg = (RadioGroup) findViewById(R.id.radioGroup1);
// Setup a listener to save chosen answer
rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if(checkedId > -1) {
QuestionAndAnswer qna = quiz.get(currentQuestion);
qna.selectedAnswer = ((RadioButton) group.findViewById(checkedId)).getText().toString();
qna.selectedId = checkedId;
}
}
});
String[] question = {"Bilangan Rokaat Solah Zuhur ?","Bilangan Rokaat Solat Subuh ?","Bilangan Rokaat Solat Maghrib ?"};
String[] answer = { "4 rokaat","2 rokaat","3 rokaat" };
String[] distractor = { "5 rokaat","1 rokaat","4 rokaat","2 rokaat","3 rokaat","4 rokaat","4 rokaat","5 rokaat","3 rokaat" };
ArrayList<String> distractorList = Arrays.asList(distractor); //error on this line
int length = question.length;
for(int i = 0; i < length; i++)
quiz.add(new QuestionAndAnswer(question[i], answer[i], distractorList.subList(i * 3, (i + 1) * 3)));
Collection.shuffle(quiz); //error here
fillInQuestion();
}
public void fillInQuestion() {
QuestionAndAnswer qna = quiz.get(currentQuestion);
tv.setText(qna.question);
// Set all of the answers in the RadioButtons
int count = rg.getChildCount();
for(int i = 0; i < count; i++)
((RadioButton) rg.getChildAt(i)).setText(qna.allAnswers.get(i));
// Restore selected answer if exists otherwise clear previous question's choice
if(qna.selectedId > -1)
rg.check(qna.selectedId);
else
rg.clearCheck();
}
}
Versuchen 'public List allAnswers ändern;' auf 'public Arraylist allAnswers;' –
Ich habe diese Methode versuchen, bevor, aber es hat nicht funktioniert. –