Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.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 无法解决方法makeText_Java_Android - Fatal编程技术网

Java 无法解决方法makeText

Java 无法解决方法makeText,java,android,Java,Android,我刚开始开发,我买了一本书,叫做《机器人编程大书呆子牧场指南》。我完成了第二章,在这个应用程序上一切都很好,它向我展示了如何制作。现在我试着在最后完成挑战,但它不起作用。这给了我一个错误,因为我根本没有改变什么,它昨天起作用了。挑战要求我在混音中添加上一个按钮 无法解析方法“makeText(匿名android.view.view.OnClickListener,int,int)” 错误就在我试图创建祝酒词的最底部 package com.example.lthol.geoquiz; impo

我刚开始开发,我买了一本书,叫做《机器人编程大书呆子牧场指南》。我完成了第二章,在这个应用程序上一切都很好,它向我展示了如何制作。现在我试着在最后完成挑战,但它不起作用。这给了我一个错误,因为我根本没有改变什么,它昨天起作用了。挑战要求我在混音中添加上一个按钮

无法解析方法“makeText(匿名android.view.view.OnClickListener,int,int)”

错误就在我试图创建祝酒词的最底部

package com.example.lthol.geoquiz;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class QuizActivity extends AppCompatActivity {

    private Button mTrueButton;
    private Button mFalseButton;
    private Button mNextButton;
    private Button mPrevButton;
    private TextView mQuestionTextView;

    private Question[] mQuestionBank = new Question[] {
            new Question(R.string.question_australia, true),
            new Question(R.string.question_oceans, true),
            new Question(R.string.question_mideast, false),
            new Question(R.string.question_africa, false),
            new Question(R.string.question_americas, true),
            new Question(R.string.question_asia, true),
    };

    private int mCurrentIndex = 0;

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

        mQuestionTextView = (TextView) findViewById(R.id.question_text_view);

        mTrueButton = (Button) findViewById(R.id.true_button);
        mTrueButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                checkAnswer(true);
            }
        });

        mFalseButton = (Button) findViewById(R.id.false_button);
        mFalseButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                checkAnswer(false);
            }
        });

        mNextButton = (Button) findViewById(R.id.next_button);
        mNextButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCurrentIndex = (mCurrentIndex + 1) % mQuestionBank.length;
                updateQuestion();

        mPrevButton = (Button) findViewById(R.id.prev_button);
        mPrevButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mCurrentIndex = (mCurrentIndex - 1) % mQuestionBank.length;
                        updateQuestion();

            }
        });

        updateQuestion();
    }

    private void updateQuestion() {
        int question = mQuestionBank[mCurrentIndex].getTextResId();
        mQuestionTextView.setText(question);
    }

    private void checkAnswer(boolean userPressedTrue) {
        boolean answerIsTrue = mQuestionBank[mCurrentIndex].isAnswerTrue();

        int messageResId = 0;

        if (userPressedTrue == answerIsTrue) {
            messageResId = R.string.correct_toast;
        } else {
            messageResId = R.string.incorrect_toast;
        }

        Toast.makeText(this, messageResId, Toast.LENGTH_SHORT)
                .show();
    }
}

mPrevButton onClick侦听器实际上包含在mNextButton实现中。您需要关闭括号,使它们分开。

您的代码和投诉不一致。请确保问题中的代码与给出错误的代码相同。您不会从该代码中获得引用的错误。您可能会忽略这些错误如果您的
Toast.makeText()
代码在一个
OnClickListener
onClick()
方法中,则不会出现此错误。在android studio中,提供的代码的最底部有下划线,并显示“无法解决方法makeText…”您的
onClickc()中似乎缺少一些右括号
方法,这些方法可能会导致您的问题。