Android studio运行启动虚拟机后,软件打不开显示一直停止运行。

Android studio运行启动虚拟机后,软件打不开显示一直停止运行。

这是我的源代码,报错日志截图在后面(初学者,做一个确认选择按钮,实现点击反应)

MainActivity.java

package com.example.wnel2;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import static com.example.wnel2.R.id.btnok;

public abstract class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private RadioGroup rg;
    private Button btnok;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        rg=findViewById(R.id.rg);
//        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(RadioGroup group, int i) {RadioButton rb=findViewById(i);Toast.makeText(MainActivity.this,"你选择的角色是:"+rb.getText().toString(),Toast.LENGTH_SHORT).show();
//            }
//        });0
        btnok=findViewById(R.id.btnok);
        btnok.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        for (int i = 0; i < rg.getChildCount(); i++) {
            RadioButton rb = (RadioButton) rg.getChildAt(i);
            Toast.makeText(this, "你的选择是:" + rb.getText().toString(), Toast.LENGTH_SHORT).show();
        }
    }
}

activity_main.xml


<LinearLayout 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="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">


    <ImageView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:src="@drawable/xcm"
        android:layout_gravity="center_horizontal"
        />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="请选择角色"
        android:gravity="center_horizontal"
        android:textSize="18sp"
        />

    <RadioGroup
        android:id="@+id/rg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <RadioButton
            android:id="@+id/rb_a"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="熊大" />

        <RadioButton
            android:id="@+id/rb_b"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="熊二" />

        <RadioButton
            android:id="@+id/rb_c"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="光头强" />


    RadioGroup>
    <Button
        android:id="@+id/btnok"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="确定"
        android:textSize="16sp"/>


LinearLayout>

详情截图如下:

img

img

img

img

img

img

img

求解决

img


去掉abstract

抽象类是这么用的吗?
抽象类是无法实例化的,无法创建对象的,所以设计抽象类就是用来被子类继承的。