Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 运行应用程序android.content.res.Resources$NotFoundException时出错:字符串资源ID#0x0_Java_Android_Sqlite_Android Studio - Fatal编程技术网

Java 运行应用程序android.content.res.Resources$NotFoundException时出错:字符串资源ID#0x0

Java 运行应用程序android.content.res.Resources$NotFoundException时出错:字符串资源ID#0x0,java,android,sqlite,android-studio,Java,Android,Sqlite,Android Studio,运行此应用程序时,我正在开发一个测验应用程序。将最小sdk从16更改为19后,我遇到错误android.content.res.Resources$NotFoundException:String resource ID#0x0。请帮助我运行此应用程序 这是我的activity_main.xml文件 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android

运行此应用程序时,我正在开发一个测验应用程序。将最小sdk从16更改为19后,我遇到错误android.content.res.Resources$NotFoundException:String resource ID#0x0。请帮助我运行此应用程序

这是我的activity_main.xml文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.awwalsoft.javaplay.MainActivity">




    <LinearLayout
        android:id="@+id/data_list"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:orientation="horizontal"
            android:layout_weight="3"
            android:layout_width="match_parent"
            android:layout_height="0dp">
            <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/card_view1"
                android:layout_weight="2"
                android:layout_width="0dp"
                android:onClick="startGame"
                android:layout_height="match_parent">

                <LinearLayout

                    android:layout_width="match_parent"
                    android:orientation="vertical"
                    android:layout_height="match_parent">

                    <ImageView
                        android:layout_marginTop="@dimen/eightdpmargin"
                        android:src="@drawable/play"
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        android:layout_weight="2"/>
                    <TextView
                        android:text="@string/start"
                        android:gravity="center"
                        android:fontFamily="sans-serif-light"
                        android:textSize="@dimen/twozerotext"
                        android:textColor="@android:color/black"
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        android:layout_weight="1"/>


                </LinearLayout>
            </android.support.v7.widget.CardView>
            <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/card_view1_1"
                android:layout_weight="1"
                android:layout_width="0dp"
                android:layout_height="match_parent">
                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">


                    <TextView
                        android:background="@drawable/scoreboard"
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        android:id="@+id/highscore"
                        android:gravity="center"
                        android:textSize="@dimen/textsizebutton"
                        android:layout_marginTop="@dimen/eightdpmargin"
                        android:layout_weight="2"/>


                    <TextView
                        android:text="@string/highscore"
                        android:gravity="center"
                        android:fontFamily="sans-serif-light"
                        android:textSize="@dimen/twozerotext"
                        android:textColor="@android:color/black"
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        android:layout_weight="1"/>


                </LinearLayout>

            </android.support.v7.widget.CardView>



        </LinearLayout>

        <TextView
            android:text="@string/useapps"
            android:layout_marginTop="@dimen/eightdpmargin"
            android:textColor="@color/colorPrimaryDark"
            android:textSize="@dimen/sptextsize2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />


        <LinearLayout
            android:orientation="horizontal"
            android:layout_weight="3"
            android:layout_marginTop="@dimen/eightdpmargin"
            android:layout_width="match_parent"
            android:layout_height="0dp">


            <HorizontalScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scrollbars="horizontal">

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:orientation="horizontal">



            <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/card_view2"
                android:layout_width="@dimen/minhigh"
                android:onClick="javaBasicsLearningApp"
                android:layout_marginEnd="@dimen/cardviewmarginright"
                android:layout_height="match_parent">

                <LinearLayout

                    android:layout_width="match_parent"
                    android:orientation="vertical"
                    android:layout_height="match_parent">

                    <ImageView
                        android:layout_marginTop="@dimen/eightdpmargin"
                        android:src="@drawable/jbl"
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        android:layout_weight="2"/>
                    <TextView
                        android:text="@string/jbl"
                        android:gravity="center"
                        android:fontFamily="sans-serif-light"
                        android:textSize="@dimen/twozerotext"
                        android:textColor="@android:color/black"
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        android:layout_weight="1"/>


                </LinearLayout>
            </android.support.v7.widget.CardView>
            <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/card_view2_1"
                android:layout_width="@dimen/minhigh"
                android:onClick="javaDeepLearningApp"
                android:layout_marginEnd="@dimen/eightdpmargin"
                android:layout_height="match_parent">
                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
                    <ImageView
                        android:layout_marginTop="@dimen/eightdpmargin"
                        android:src="@drawable/jdl"
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        android:layout_weight="2"/>
                    <TextView
                        android:text="@string/jdl"
                        android:gravity="center"
                        android:fontFamily="sans-serif-light"
                        android:textSize="@dimen/twozerotext"
                        android:textColor="@android:color/black"
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        android:layout_weight="1"/>


                </LinearLayout>

            </android.support.v7.widget.CardView>

            <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/card_view2_2"
                android:layout_width="@dimen/minhigh"
                android:onClick="learnJdbcApp"
                android:layout_height="match_parent">
                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
                    <ImageView
                        android:layout_marginTop="@dimen/eightdpmargin"
                        android:src="@drawable/jdbc"
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        android:layout_weight="2"/>
                    <TextView
                        android:text="@string/ljdbc"
                        android:gravity="center"
                        android:fontFamily="sans-serif-light"
                        android:textSize="@dimen/twozerotext"
                        android:textColor="@android:color/black"
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        android:layout_weight="1"/>


                </LinearLayout>

            </android.support.v7.widget.CardView>

                </LinearLayout>


            </HorizontalScrollView>

        </LinearLayout>










        <LinearLayout
            android:layout_marginTop="@dimen/eightdpmargin"
            android:layout_weight="2"
            android:layout_width="match_parent"
            android:layout_height="0dp">

            <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/card_view3"
                android:onClick="helpClick"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
                    <ImageView
                        android:layout_marginTop="@dimen/eightdpmargin"
                        android:src="@drawable/help"
                        android:layout_width="0dp"
                        android:layout_margin="@dimen/sixteendppadding"
                        android:layout_height="match_parent"
                        android:layout_weight="1"/>
                    <TextView
                        android:text="@string/help"
                        android:gravity="center"
                        android:id="@+id/helptext"
                        android:fontFamily="sans-serif-light"
                        android:textSize="@dimen/textsizemain"
                        android:textColor="@android:color/black"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1"/>


                </LinearLayout>

            </android.support.v7.widget.CardView>

        </LinearLayout>

    </LinearLayout>

  </LinearLayout>
这是我的PlayGame.java文件

package com.awwalsoft.javaplay;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    String moreApps1 = "com.awwalsoft.javabasicslearning";
    String moreApps2 = "com.awwalsoft.javadeeplearning";
    String moreApps3 = "com.awwalsoft.learnjdbc";
    private Player currentPlayer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        currentPlayer = ((JavaPlay) getApplication()).player; //gets player from lightquiz application
        updateHighScore();


    }

    public void javaBasicsLearningApp(View v){


        try {
            startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("market://details?id=" + moreApps1)));
        } catch (android.content.ActivityNotFoundException e) {
            startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://play.google.com/store/apps/details?id=" + moreApps1)));
        }


    }

    public void javaDeepLearningApp(View v){

        try {
            startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("market://details?id=" + moreApps2)));
        } catch (android.content.ActivityNotFoundException e) {
            startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://play.google.com/store/apps/details?id=" + moreApps2)));
        }


    }

    public void learnJdbcApp(View v){

        try {
            startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("market://details?id=" + moreApps3)));
        } catch (android.content.ActivityNotFoundException e) {
            startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://play.google.com/store/apps/details?id=" + moreApps3)));
        }


    }

    public void helpClick(View view){
        Intent helpIntent = new Intent(this,Help.class);
        startActivity(helpIntent);
    }

    @Override
    public void onResume() {
        super.onResume();
        ((JavaPlay) this.getApplicationContext()).clearQuestions();
        updateHighScore();
    }
    @Override
    public void onBackPressed() {
        this.finish();
    }

    public void startGame(View view) {

                Intent intent = new Intent(this, PlayGame.class);
                startActivity(intent);


    }

    void selecGenre() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.dialog_title);
        String[] genres = QuestionGenre.names();
        builder.setItems(QuestionGenre.names(), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                beginQuizGame(QuestionGenre.names()[which]);
            }
        });

        AlertDialog dialog = builder.create();
        dialog.show();
    }

    void beginQuizGame(String genre) {
        Intent intent = new Intent(this, PlayGame.class);
        intent.putExtra("Genre", genre);
        startActivity(intent);

    }

    private void updateHighScore() {
        TextView highScoreText = (TextView) findViewById(R.id.highscore);
        highScoreText.setText(currentPlayer.getHighScore());
    }

}
package com.awwalsoft.javaplay;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import java.io.IOException;

public class PlayGame extends AppCompatActivity {
    private final int questionsDelay = 500;
    private final int questionsPoints = 10;
    private final int questionSeconds = 8;
    private int points;
    private int lives;
    private int correctAnswer;
    //Layout Stuff
    private ImageView correctImg;
    private ImageView wrongImg;
    private ImageView questionImg;
    private TextView questionText;
    private Button soundButton;
    private TextView pointsText;
    private TextView lifeText;
    private TextView countdownText;
    private Button[] answerButtons = new Button[4];

    private CountDownTimer countdown;
    private QuestionsGenerator generator;
    private ProgressDialog progress;

    private String genreSelection = null;
    private boolean gameFinished = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_play_game);

        Intent intent = getIntent();
        genreSelection = intent.getStringExtra("Genre");


        progress = new ProgressDialog(this);
        progress.setMessage("Loading Database ");
        progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progress.setIndeterminate(true);
        progress.show();



        new Thread(new Runnable() {
            public void run() {
                try {
                    loadQuestions();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                loadLayout();


                runOnUiThread(new Runnable() {
                    public void run() {
                        startGame();
                    }
                });
            }
        }).start();
    }


    @Override
    public void onPause() {
        super.onPause();
        countdown.cancel();
        hideQuestionMultimedia();
        this.finish();
        gameFinished = true;
        // gameOver();

    }


    @Override
    public void onBackPressed() {
        // this.finish();
        gameOver();
    }

    //an answer was clicked
    public void answerClicked(View view) {
        countdown.cancel();
        int answer; //-1 by default
        buttonsActive(false);
        switch (view.getId()) {
            case R.id.answer_1:
                answer = 1;
                break;
            case R.id.answer_2:
                answer = 2;
                break;
            case R.id.answer_3:
                answer = 3;
                break;
            case R.id.answer_4:
                answer = 4;
                break;
            default:
                throw new RuntimeException("Unknown button ID");
        }
        if (correctAnswer == answer) correctAnswer();
        else wrongAnswer();
        updateTexts();
        nextQuestion();
    }

    public void soundClick(View view) {
        switch (view.getId()) {
            case R.id.sound_button:
                playSound();
                break;
            default:
                throw new RuntimeException("Unknown button ID");

        }
    }

    //set a new question from generator

    private void playSound() {
        if (!gameFinished)
            ((JavaPlay) this.getApplicationContext()).soundHandler.playQuestionSound();
    }

    private void setQuestion() {
        if (!gameFinished) {
            hideQuestionMultimedia();
            buttonsActive(true);
            Question quest = generator.getQuestion();//get a randomized question

            if (!quest.isValid()) throw new RuntimeException("Invalid Question");
            this.correctAnswer = quest.getCorrectAnswer();
            for (int i = 0; i < 4; i++)
                answerButtons[i].setText(quest.getAnswer(i)); //set questions layout

            hideAnswerImage();
            questionText.setText(quest.getText());
            QuestionType qt = quest.type();
            switch (qt) {
                case TEXT:
                    //showQuestionText(((TextQuestion) quest).text);
                    break;
                case IMAGE:
                    showQuestionImage(((ImageQuestion) quest).image);
                    break;
                case SOUND:
                    showQuestionSound(((SoundQuestion) quest).sound);
                    playSound();
                    break;
                default:
                    throw new RuntimeException("Invalid question type");
            }
            countdown = new CountDownTimer(questionSeconds * 1000, 500) {
                @Override
                public void onTick(long millisUntilFinished) {
                    countdownText.setText(Integer.toString((int) (millisUntilFinished / 1000) + 1));
            /* if(millisUntilFinished/1000 == 1) {
                 wrongAnswer();
                 updateTexts();
                 nextQuestion();
             }*/
                }

                @Override
                public void onFinish() {
                    buttonsActive(false);
                    wrongAnswer();
                    updateTexts();
                    nextQuestion();
                }
            }.start();
        }
    }

    private void showQuestionSound(String sound) {
        soundButton.setVisibility(View.VISIBLE);
        soundButton.setClickable(true);
        ((JavaPlay) this.getApplicationContext()).soundHandler.setQuestionSound(sound);
    }

    private void showQuestionImage(String imagename) {
        int resourceId = this.getResources().getIdentifier(imagename, "drawable", this.getPackageName());
        questionImg.setImageResource(resourceId);
        questionImg.setVisibility(View.VISIBLE);
        //questionImg.setMaxHeight();
    }

    private void hideQuestionMultimedia() {
        questionImg.setVisibility(View.INVISIBLE);
        soundButton.setVisibility(View.INVISIBLE);
        ((JavaPlay) this.getApplicationContext()).soundHandler.stopQuestionSound();
        soundButton.setClickable(false);
    }
    //next question after som time
    private void nextQuestion() {
        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (generator.size() == 0) gameOver(); //no more questions left
                else setQuestion();
            }
        }, questionsDelay);
    }

    //What happens when a correct answer was clicked
    private void correctAnswer() {
        points += questionsPoints;
        wrongImg.setVisibility(View.INVISIBLE);
        correctImg.setVisibility(View.VISIBLE);
        ((JavaPlay) this.getApplicationContext()).soundHandler.playCorrectSound();
    }

    //What happens when a wrong answer was clicked
    private void wrongAnswer() {
        correctImg.setVisibility(View.INVISIBLE);
        wrongImg.setVisibility(View.VISIBLE);
        ((JavaPlay) this.getApplicationContext()).soundHandler.playWrongSound();
        lives--;
        if (lives == 0) gameOver();
    }

    //Hides any answer image (tick or cross)
    private void hideAnswerImage() {
        correctImg.setVisibility(View.INVISIBLE);
        wrongImg.setVisibility(View.INVISIBLE);
    }

    private void buttonsActive(boolean b) {
        for (Button button : answerButtons) {
            button.setClickable(b);
        }
    }

    private void loadLayout() {
        correctImg = (ImageView) findViewById(R.id.correct_img);
        wrongImg = (ImageView) findViewById(R.id.wrong_img);
        pointsText = (TextView) findViewById(R.id.points_text);
        lifeText = (TextView) findViewById(R.id.life_text);
        countdownText = (TextView) findViewById(R.id.countdown_text);
        questionImg = (ImageView) findViewById(R.id.question_image);
        questionText = (TextView) findViewById(R.id.question);
        soundButton = (Button) findViewById(R.id.sound_button);

        answerButtons[0] = (Button) findViewById(R.id.answer_1);
        answerButtons[1] = (Button) findViewById(R.id.answer_2);
        answerButtons[2] = (Button) findViewById(R.id.answer_3);
        answerButtons[3] = (Button) findViewById(R.id.answer_4);

        hideAnswerImage();
    }

    //Updates life and score texts
    private void updateTexts() {
        lifeText.setText("Life:" + lives);
        pointsText.setText("Score:" + points);
        countdownText.setText("");
    }

    private void gameOver() {
        //hideQuestionMultimedia();
        gameFinished = true;
        ((JavaPlay) this.getApplicationContext()).soundHandler.stopQuestionSound();
        soundButton.setClickable(false);
        countdown.cancel();
        buttonsActive(false);
        Intent intent = new Intent(this, GameOver.class);
        intent.putExtra("Score", points);
        startActivity(intent);
        this.finish();
    }

    //reloads questions from xml (old)
   /* private void reload_questions() throws IOException, XmlPullParserException {
        XmlResourceParser xmlq = getResources().getXml(R.xml.questions);
        MainActivity.generator.loadQuestions(xmlq);
        xmlq.close();
    }*/

    //Starts game
    private void startGame() {
        points = 0;
        lives = 3;
        gameFinished = false;
        buttonsActive(true);
        updateTexts();
        setQuestion();
        progress.dismiss();
        Toast toast = Toast.makeText(this, "Quiz is Ready", Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
        View fore = findViewById(R.id.foreground);
        fore.setVisibility(View.INVISIBLE);
    }


    private void loadQuestions() throws IOException {
        if (!Question.isQuestionListReady()) {
            ((JavaPlay) this.getApplicationContext()).loadRawQuestions(genreSelection);
        }
        this.generator = new QuestionsGenerator();
    }
}
package com.awwalsoft.javaplay;
导入android.app.ProgressDialog;
导入android.content.Intent;
导入android.os.Bundle;
导入android.os.CountDownTimer;
导入android.os.Handler;
导入android.support.v7.app.AppActivity;
导入android.view.Gravity;
导入android.view.view;
导入android.widget.Button;
导入android.widget.ImageView;
导入android.widget.TextView;
导入android.widget.Toast;
导入java.io.IOException;
公共类游戏扩展应用程序活动{
私人最终智力问题显示=500;
私人最终整数问题点数=10;
私人最终整数秒=8;
私人积分;
私人生活;
私人回答;
//布局材料
私人影像视图校正;
私有图像视图错误img;
私人影像视图问题;
私有文本查看问题文本;
私人按钮声音按钮;
私有文本视图点文本;
私有文本查看生活文本;
私有文本查看倒计时文本;
私有按钮[]应答按钮=新按钮[4];
私人倒计时;
私人问题发生器;
私人进展对话进展;
私有字符串genreSelection=null;
私有布尔gameFinished=false;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u play\u game);
Intent=getIntent();
genreSelection=intent.getStringExtra(“流派”);
进度=新建进度对话框(此对话框);
setMessage(“加载数据库”);
progress.setProgressStyle(ProgressDialog.STYLE\u微调器);
progress.setUndeterminate(true);
progress.show();
新线程(newrunnable()){
公开募捐{
试一试{
加载问题();
}捕获(IOE异常){
e、 printStackTrace();
}
loadLayout();
runOnUiThread(新的Runnable(){
公开募捐{
startGame();
}
});
}
}).start();
}
@凌驾
公共无效暂停(){
super.onPause();
倒计时。取消();
hideQuestionMultimedia();
这个;
gameFinished=true;
//gameOver();
}
@凌驾
public void onBackPressed(){
//这个;
gameOver();
}
//点击了一个答案
已单击公共无效应答(视图){
倒计时。取消();
int answer;//-1默认值
按钮激活(假);
开关(view.getId()){
案例R.id.答案1:
答案=1;
打破
案例R.id.答案2:
答案=2;
打破
案例R.id.答案3:
答案=3;
打破
案例R.id.答案4:
答案=4;
打破
违约:
抛出新的RuntimeException(“未知按钮ID”);
}
如果(correctAnswer==答案)correctAnswer();
否则回答错误();
updateTexts();
nextQuestion();
}
公共void声音单击(视图){
开关(view.getId()){
外壳R.id.声音按钮:
播放声音();
打破
违约:
抛出新的RuntimeException(“未知按钮ID”);
}
}
//从生成器中设置新问题
私人音乐播放器(){
如果(!gameFinished)
((JavaPlay)this.getApplicationContext()).soundHandler.playQuestionSound();
}
私人问题{
如果(!gameFinished){
hideQuestionMultimedia();
按钮激活(真);
quest=generator.getQuestion();//获取随机问题
如果(!quest.isValid())抛出新的RuntimeException(“无效问题”);
this.correctAnswer=quest.getCorrectAnswer();
对于(int i=0;i<4;i++)
回答按钮[i].setText(quest.getAnswer(i));//设置问题布局
hideAnswerImage();
questionText.setText(quest.getText());
QuestionType qt=quest.type();
开关(qt){
案例文本:
//showQuestionText(((TextQuestion)quest.text);
打破
案例图像:
showQuestionImage(((ImageQuestion)quest.image);
打破
案例声音:
showQuestionSound(((SoundQuestion)quest.sound);
播放声音();
打破
违约:
抛出新的RuntimeException(“无效问题类型”);
}
倒计时=新倒计时(问题秒*1000500){
@凌驾
公共void onTick(长毫秒未完成){
countdownText.setText(Integer.toString((int)(millisuntiltfinished/1000)+1);
/*如果(毫秒/1000==1){
错误答案();
updateTexts();
nextQuestion();
}*/
}
@凌驾
公共无效onFinish(){
按钮激活(假);
错误答案();
updateTexts();
nextQuestion();
}
}.start();
}
}
highScoreText.setText(String.valueOf(currentPlayer.getHighScore()));
highScoreText.setText(currentPlayer.getHighScore()+"");