Android崩溃:无法实例化活动

Android崩溃:无法实例化活动,android,xml,android-studio,Android,Xml,Android Studio,AndroidManifest.xml package com.example.app_outline.Activities; import android.Manifest; import android.content.Intent; import android.content.pm.PackageManager; import android.net.Uri; import android.os.Build; import android.os.Bundle; import andro

AndroidManifest.xml

package com.example.app_outline.Activities;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import com.example.app_outline.R;




public abstract class MainActivity extends AppCompatActivity {
    static int PReqCode = 1;
    static int REQUESCODE = 1;

    ImageView ImgUserPhoto;

    Uri pickedImgUri;

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

        //inu views

        ImgUserPhoto = findViewById(R.id.regUserPhoto);

        ImgUserPhoto.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (Build.VERSION.SDK_INT >= 22) {

                    checkAndRequestForPermission();

                } else {


                    openGallery();

                }


            }
        });
    }

    private void openGallery() {
        //TODO: open gallery intent and wait for the user to pick an image!

        Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT);
        galleryIntent.setType("image/*");
        startActivityForResult(galleryIntent, REQUESCODE);


    }

    private void checkAndRequestForPermission() {

        if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {

            if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE)) {

                Toast.makeText(MainActivity.this, "Please accept the required permission", Toast.LENGTH_SHORT).show();
            } else {

                ActivityCompat.requestPermissions(MainActivity.this,
                        new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, PReqCode);
            }
        } else
            openGallery();``

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK && requestCode == REQUESCODE && data != null) {

            //the user has successfully picked an image
            //we need to save its reference to a Uri variable
            pickedImgUri = data.getData();
            ImgUserPhoto.setImageURI(pickedImgUri);


        }


    }
}
ActivityMain.xml


    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.app_outline"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

    <application
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        android:allowBackup="true">
        <activity
            android:name="com.example.app_outline.Activities.MainActivity"
            android:launchMode="singleTask"
            android:label="@string/app_name">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".BuildConfig"
            android:label="@string/app_name">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        </activity>

    </application>

</manifest>
我已经从我的应用程序中提供了一些文件 但我面临一个问题,我的应用程序崩溃了…无法打开, 应用程序一直关闭。 自从我学会编写应用程序以来,我就一直面临着这个问题,我已经添加了我的 android清单中的活动 如何克服这些关于应用程序不断停止的问题

不要将MainActivity声明为抽象类


在AndroidManifest文件中,只声明一个启动器活动。在你的情况下,主要的活动。除非必要,否则不要声明多启动器。

MainActivity是一个抽象类。您不能将抽象类声明为显式活动。我非常感谢您的帮助,先生,它成功了。

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.app_outline"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

    <application
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        android:allowBackup="true">
        <activity
            android:name="com.example.app_outline.Activities.MainActivity"
            android:launchMode="singleTask"
            android:label="@string/app_name">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".BuildConfig"
            android:label="@string/app_name">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        </activity>

    </application>

</manifest>
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
    tools:context=".Activities.MainActivity"
    android:background="#ffffff">


    <EditText
        android:background="@drawable/reg_edittext_style"
        android:hint="@string/Name"
        android:id="@+id/regName"
        android:layout_width="265dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:autofillHints=""
        android:ems="10"
        android:inputType="textPersonName"
        android:text="@string/Name"
        app:layout_constraintBottom_toTopOf="@+id/regEmail"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

    <ImageView
        android:id="@+id/regUserPhoto"
        android:layout_width="90dp"
        android:layout_height="90dp"
        android:contentDescription="@string/image"
        android:src="@drawable/userpic"
        app:layout_constraintBottom_toTopOf="@+id/regName"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <EditText
        android:background="@drawable/reg_edittext_style"
        android:hint="@string/Email_ID"
        android:id="@+id/regEmail"
        android:layout_width="265dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="188dp"
        android:autofillHints=""
        android:ems="10"
        android:inputType="textEmailAddress"
        android:text="@string/Email_ID"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <EditText
        android:background="@drawable/reg_edittext_style"
        android:hint="@string/Password"
        android:id="@+id/regPassword"
        android:layout_width="265dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="312dp"
        android:ems="10"
        android:inputType="textPassword"
        android:text="@string/Password"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        android:autofillHints="" />

    <EditText
        android:background="@drawable/reg_edittext_style"
        android:hint="@string/Confirm_Password"
        android:id="@+id/regPassword2"
        android:layout_width="265dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="256dp"
        android:ems="10"
        android:inputType="textPassword"
        android:text="@string/Confirm_Password"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        android:autofillHints="" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="44dp"
        android:background="@drawable/reg_btn_style"
        android:hint="@string/register"
        android:text="@string/register"
        android:textColor="#ffffff"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.498"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/regPassword2" />

    <ProgressBar
        android:id="@+id/progressBar2"
        style="?android:attr/progressBarStyle"
        android:layout_width="155dp"
        android:layout_height="wrap_content"
        android:background="@drawable/reg_btn_style"
        app:layout_constraintBottom_toBottomOf="@+id/button"
        app:layout_constraintEnd_toEndOf="@+id/button"
        app:layout_constraintStart_toStartOf="@+id/button"
        app:layout_constraintTop_toTopOf="@+id/button"
        app:layout_constraintVertical_bias="0.0" />


</androidx.constraintlayout.widget.ConstraintLayout>