1

I'm developing a "question and answer" Android app. When a user chooses a wrong answer, the game ends and this question and its answer are imported to a database. But I have a problem, I can import the question and its answer to the database but the second action (game is finished and the result is displayed) doesn't work. How can I fix this?

This is my choose answer method:

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();
    }
}

This is the 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)
Ben
  • 51,770
  • 36
  • 127
  • 149
mr Z
  • 119
  • 1
  • 3
  • 9
  • 2
    11-11 01:58:29.763: E/AndroidRuntime(276): at pk.aeh.ideos.taa.PlayGame.lietke_congviec(PlayGame.java:633) dont nothing about this line and the context so cant give an answer – Fabian Knapp Nov 11 '12 at 11:35
  • Which line in your code example is line 633? – Valentino Ru Nov 11 '12 at 11:50
  • i cant post all of logcat, it's so long. please check this txt file :http://www.mediafire.com/view/?0ekoncnzag7kwfk – mr Z Nov 11 '12 at 12:12

0 Answers0