2020-04-04 18:14:41.474 23444-23444/com.example.app_outline E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.app_outline, PID: 23444
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.app_outline/com.example.app_outline.Activities.MainActivity}: java.lang.InstantiationException: java.lang.Class<com.example.app_outline.Activities.Main``Activity> cannot be instantiated
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3268)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3488)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2049)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7506)
at java.lang
Это ошибки в моем Logcat
Код MainActivity
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);
}
}
}
AndroidManifest. 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>
ActivityMain. xml
<?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>
Я дал несколько файлов из моего приложения, но я столкнулся с проблемой, что мое приложение зависает ... и не открывается, что приложение продолжает закрываться. Я сталкиваюсь с этой проблемой с тех пор, как научился кодировать приложение. Я добавил свою активность в android манифест, как преодолеть эти проблемы, связанные с остановкой приложения