Ошибка с символом MainActivity $ 2, но фактически не связана с активностью? - PullRequest
0 голосов
/ 17 марта 2020

Я новичок в программировании и android студии и в настоящее время работаю над домашним заданием по разработке quiz app. Приложение работало нормально, пока я не получил эту ошибку:

Тип com.example.quizapp.MainActivity $ 2 определяется несколько раз: / Users / laurapaulino / Desktop / Mobile Computing / QuizApp2 / app / build / Промежуточные / javac / debug / classes / com / example / quizapp / MainActivity $ 2 2.class, / Users / laurapaulino / Desktop / Мобильные вычисления / QuizApp2 / app / build / промежуточные / javac / debug / classes / com / example / quizapp / MainActivity $ 2.class

пакет com.example.quizapp;

import android.view.View;
import android.view.View.OnClickListener;

class MainActivity$2 implements OnClickListener {
    MainActivity$2(MainActivity this$0) {
        this.this$0 = this$0;
    }

    public void onClick(View view) {
        if (this.this$0.answer2.getText() == MainActivity.access$000(this.this$0)) {
            MainActivity.access$108(this.this$0);
            this.this$0.score.setText("Score: " + MainActivity.access$100(this.this$0));
            MainActivity.access$300(this.this$0, this.this$0.r.nextInt(MainActivity.access$200(this.this$0)));
        } else {
            MainActivity.access$400(this.this$0);
        }

    }
}

Image

Так выглядит мой класс Main Activity подобно. Не могу найти, где ошибка ...

package com.example.quizapp;

import androidx.appcompat.app.AppCompatActivity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.util.Random;

public class MainActivity extends AppCompatActivity {

    Button answer1, answer2, answer3, answer4;

    TextView score, question;

    private Questions mQuestions = new Questions();

    private String mAnswers;
    private int mScore = 0;
    private int mQuestionsLength = mQuestions.mQuestions.length;

    Random r;

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

        r = new Random();

        answer1 = (Button) findViewById(R.id.answer1);
        answer2 = (Button) findViewById(R.id.answer2);
        answer3 = (Button) findViewById(R.id.answer3);
        answer4 = (Button) findViewById(R.id.answer4);

        score = (TextView) findViewById(R.id.score);
        question = (TextView) findViewById(R.id.question);

        score.setText("Score: " + mScore);

        updateQuestion(r.nextInt(mQuestionsLength));

        answer1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (answer1.getText() == mAnswers){
                    mScore++;
                    score.setText("Score: " + mScore);
                    updateQuestion(r.nextInt(mQuestionsLength));
                } else {
                    gameOver();
                }
            }

        });


        answer2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (answer2.getText() == mAnswers){
                    mScore++;
                    score.setText("Score: " + mScore);
                    updateQuestion(r.nextInt(mQuestionsLength));
                } else {
                    gameOver();
                }
            }

        });

        answer3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (answer3.getText() == mAnswers){
                    mScore++;
                    score.setText("Score: " + mScore);
                    updateQuestion(r.nextInt(mQuestionsLength));
                } else {
                    gameOver();
                }
            }

        });

        answer4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (answer4.getText() == mAnswers){
                    mScore++;
                    score.setText("Score: " + mScore);
                    updateQuestion(r.nextInt(mQuestionsLength));
                } else {
                    gameOver();
                }
            }

        });

    }

    private void updateQuestion(int num ) {
        question.setText(mQuestions.getQuestion(num));
        answer1.setText(mQuestions.getChoice1(num));
        answer2.setText(mQuestions.getChoice2(num));
        answer3.setText(mQuestions.getChoice3(num));
        answer4.setText(mQuestions.getChoice4(num));

        mAnswers = mQuestions.getCorrectAnswer(num);
    }

    private void gameOver() {
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MainActivity.this);
        alertDialogBuilder
                .setMessage("Game Over! Your score is " + mScore + " points.")
                .setCancelable(false)
                .setPositiveButton("NEW GAME",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int i) {
                                startActivity(new Intent(getApplicationContext(), MainActivity.class));
                                finish();
                            }
                        })
                .setNegativeButton("EXIT",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int i) {
                                finish();
                            }
                        });

        AlertDialog alertDialog = alertDialogBuilder.create();
        alertDialog.show();

    }
}

Секунда Java Класс:

package com.example.quizapp;

public class Questions {
    public String mQuestions[] = {
            "Who is the oldest Belcher kid?",
            "What is Linda's sister's name?",
            "Where do Linda's parents live?",
            "What is Bob's favorite holiday?",
            "Who is Bob's best friend?",
            "Who is Bob's arch enemy?",
            "What is Louise's favorite toy?",
            "Who was Gene's first girlfriend?",
            "Who did Gayle have a big crush on in high school?"
    };

    private String mChoices[][] = {
            //"Tina", "Gayle", "Florida", "Thanksgiving", "Teddy", "Jimmy Pesto", "Kuchi Kopi", "Courtney", "Derek Dematopolis"
            {"Tina", "Courtney", "Louise", "Gene"},
            {"Gretchen", "Teddy", "Gayle", "Maria"},
            {"New Jersey", "New York", "King's Head Island", "Florida"},
            {"Halloween", "Thanksgiving", "Christmas", "Easter"},
            {"Mr. Fischoeder", "Gayle", "Teddy", "Hugo"},
            {"Jimmy Pesto", "Mr. Fischoeder", "Ron", "Randy"},
            {"Teddy Bear", "Rare Pony", "Kuchi Kopi", "Tricycle"},
            {"Millie", "Tammy", "Jocelyn", "Courtney"},
            {"Gretchen", "Felix Fischoeder", "Dr. Yap", "Derek Dematopolis"},
    };


    private String mCorrectAnswers[] = {"Tina", "Gayle", "Florida", "Thanksgiving", "Teddy", "Jimmy Pesto", "Kuchi Kopi", "Courtney", "Derek Dematopolis"};

    public String getQuestion (int a) {
        String question = mQuestions[a];
        return question;
    }

    public String getChoice1(int a) {
        String choice = mChoices[a][0];
        return choice;
    }

    public String getChoice2(int a) {
        String choice = mChoices[a][1];
        return choice;
    }

    public String getChoice3(int a) {
        String choice = mChoices[a][2];
        return choice;
    }

    public String getChoice4(int a) {
        String choice = mChoices[a][3];
        return choice;
    }

    public String getCorrectAnswer(int a) {
        String answer = mCorrectAnswers[a];
        return answer;
    }

}

Нет никаких признаков ошибки на фактических классах, но я могу ' Запустите программу на эмуляторе. Буду признателен за помощь. Спасибо!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...