sqlite W/ActivityThread:handleWindowVisibility:内标识android.os.BinderProxy@51185c2 Android Studio无活动

csga3l58  于 2022-11-15  发布在  SQLite
关注(0)|答案(1)|浏览(116)

我正在试着做一个小的问答应用程序来测试。然而,当用户已经选择玩游戏时,该错误出现:w/ActivityThread:handleWindowVisibility:令牌android.os.BinderProxy@51185c2没有活动
从昨天开始,我一直在寻找这个问题的类似帖子,但我仍然没有找到解决方案。
我尝试清理和重建我的项目,仍然不起作用(尽管当我这样做时,我也收到了一个新的错误:w/system:a resource to call Close。我试着打开和关闭Android Studio,不工作,同样的问题再次出现。
我通过我创建的SQLite数据库来回答我的问题。
这是在我的seltQuiz类中设置意图的代码

choiceButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int checkedBtn = rgChoices.getCheckedRadioButtonId();
                switch (checkedBtn) {
                    case R.id.rbBeginner:
                        Intent i = new Intent(getApplicationContext(), quizGameActivity.class);
                        startActivity(i);
                        break;
                    default:
                        Toast.makeText(quizSelectionActivity.this, "Please select a level", Toast.LENGTH_SHORT).show();
                        break;
                }
            }
        });

这是我的quizGameActivity代码

package com.example.computerknowledgequiz;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;

import java.util.Collections;
import java.util.List;

public class quizGameActivity extends AppCompatActivity {

    private TextView questionText;
    private Button a1Btn, a2Btn, a3Btn, a4Btn, nextQuestionBtn;
    private List<Question> questions;
    private int questionCounter, questionCountTotal;
    private Question currentQuestion;
    private boolean answered;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_quiz_game);
        questionText = findViewById(R.id.questionText);
        a1Btn = findViewById(R.id.a1Btn);
        a2Btn = findViewById(R.id.a2Btn);
        a3Btn = findViewById(R.id.a3Btn);
        a4Btn = findViewById(R.id.a4Btn);
        nextQuestionBtn = findViewById(R.id.nextQuestionBtn);

        QuestionsDatabase questionsDB = new QuestionsDatabase(this);
        questions = questionsDB.getAllQuestions();
        questionCountTotal = questions.size();
        Collections.shuffle(questions);

        moveToNextQuestion();
    }

    private void moveToNextQuestion() {
        if (questionCounter < questionCountTotal) {
            currentQuestion = questions.get(questionCounter);

            questionText.setText(currentQuestion.getQuestion());
            a1Btn.setText(currentQuestion.getAnswer1());
            a2Btn.setText(currentQuestion.getAnswer2());
            a3Btn.setText(currentQuestion.getAnswer3());
            a4Btn.setText(currentQuestion.getAnswer4());

            questionCounter++;
            answered = false;

        } else {
            finish();
        }
    }
}

这是quizGame.xml代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:gravity="center"
    tools:context=".MainActivity"
    android:id="@+id/relLayout">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"
        android:src="@drawable/ic_background_image" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:gravity="center"
        android:id="@+id/linearLayout">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="100dp"
            android:fontFamily="@font/comfortaa"
            android:gravity="center"
            android:text="This is the question field"
            android:textColor="@color/white"
            android:textSize="30sp"
            android:textStyle="bold"
            android:id="@+id/questionText"/>

        <Button
            android:id="@+id/a1Btn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="40dp"
            android:layout_marginLeft="25dp"
            android:layout_marginRight="25dp"
            android:backgroundTint="@color/black"
            android:fontFamily="@font/comfortaa"
            android:text="" />

        <Button
            android:id="@+id/a2Btn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="40dp"
            android:layout_marginLeft="25dp"
            android:layout_marginRight="25dp"
            android:backgroundTint="@color/black"
            android:fontFamily="@font/comfortaa"
            android:text="" />

        <Button
            android:id="@+id/a3Btn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="40dp"
            android:layout_marginLeft="25dp"
            android:layout_marginRight="25dp"
            android:backgroundTint="@color/black"
            android:fontFamily="@font/comfortaa"
            android:text="" />

        <Button
            android:id="@+id/a4Btn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="40dp"
            android:layout_marginLeft="25dp"
            android:layout_marginRight="25dp"
            android:backgroundTint="@color/black"
            android:fontFamily="@font/comfortaa"
            android:text="" />

        <Button
            android:id="@+id/nextQuestionBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="60dp"
            android:backgroundTint="@color/black"
            android:fontFamily="@font/comfortaa"
            android:text="@string/nextBtnEng" />

    </LinearLayout>

</RelativeLayout>

如果需要提供任何进一步的代码,我将很乐意。
谢谢大家。

cgyqldqp

cgyqldqp1#

我找到了解决方案,其实很简单。
在运行该应用程序之前,我忘了调用填充QuestionsTable()方法,该方法将用Query对象填充数据库。
因此,当游戏活动开始时,我的setText(getString())方法没有文本。

相关问题