我正在开发一个“问答”Android 应用程序。当用户选择错误答案时,游戏结束,并且该问题及其答案被导入数据库。但是我有一个问题,我可以将问题及其答案导入数据库,但第二个动作(游戏结束并显示结果)不起作用。我怎样才能解决这个问题?
这是我选择的答案方法:
private void onOptionSelected(String option){
if(!isGamePaused && !isGameEnded) {
ATriviaQuestion tTQuestion = myListOfTriviaQuestions.get(currentQuestionNumber);
if(option.equals(tTQuestion.GetOptions().get(tTQuestion.GetAnswer() - 1))) {
correct += 1;
remainingTime = mySecondsPassed;
totalPoints += remainingTime * pointsPerRemainingSecond;
totalPoints += pointsPerCorrectAnswer;
}
else{ questionsAsked = totalQuestions;
incorrect += 1;
totalPoints -= pointsPerWrongAnswer;
DisplayResults();
EndGame();
database db= new database(this);
db.insertData(new ListOfData(myListOfTriviaQuestions.get(currentQuestionNumber).GetQuestion(),tTQuestion.GetOptions().get(tTQuestion.GetAnswer() - 1)));
loadListViewData(); ;
}
mySecondsPassed = config.GetTimeToAnswer();
UpdateTimerColors(mySecondsPassed);
if(questionsAsked >= totalQuestions){
isGameEnded=true;
EndGame();
DisplayResults();
} else {
currentQuestionNumber=GenerateQuestionNumber();
PopulateQuestion();
}
}else{
PausedOrEndedGameResponse();
}
}
这是 LogCat:
11-11 01:58:29.763: E/AndroidRuntime(276): FATAL EXCEPTION: main
11-11 01:58:29.763: E/AndroidRuntime(276): java.lang.NullPointerException
11-11 01:58:29.763: E/AndroidRuntime(276): at pk.aeh.ideos.taa.PlayGame.lietke_congviec(PlayGame.java:633)
11-11 01:58:29.763: E/AndroidRuntime(276): at pk.aeh.ideos.taa.PlayGame.onOptionSelected(PlayGame.java:229)
11-11 01:58:29.763: E/AndroidRuntime(276): at pk.aeh.ideos.taa.PlayGame.onClick(PlayGame.java:149)
11-11 01:58:29.763: E/AndroidRuntime(276): at android.view.View.performClick(View.java:2408)
11-11 01:58:29.763: E/AndroidRuntime(276): at android.view.View$PerformClick.run(View.java:8816)
11-11 01:58:29.763: E/AndroidRuntime(276): at android.os.Handler.handleCallback(Handler.java:587)
11-11 01:58:29.763: E/AndroidRuntime(276): at android.os.Handler.dispatchMessage(Handler.java:92)
11-11 01:58:29.763: E/AndroidRuntime(276): at android.os.Looper.loop(Looper.java:123)
11-11 01:58:29.763: E/AndroidRuntime(276): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-11 01:58:29.763: E/AndroidRuntime(276): at java.lang.reflect.Method.invokeNative(Native Method)
11-11 01:58:29.763: E/AndroidRuntime(276): at java.lang.reflect.Method.invoke(Method.java:521)
11-11 01:58:29.763: E/AndroidRuntime(276): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-11 01:58:29.763: E/AndroidRuntime(276): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-11 01:58:29.763: E/AndroidRuntime(276): at dalvik.system.NativeStart.main(Native Method)