无法运行我的应用程序它不断崩溃(android.content.ActivityNotFoundException)

问题描述 投票:0回答:2

我一直在开发一个应用程序,当我运行代码并尝试进入该应用程序时,它告诉我该应用程序由于某种原因已停止(可能崩溃),当我进入 logcat 查看我发现的进程时一个错误(

 android.content.ActivityNotFoundException: Unable to find explicit activity class
),我根本不明白

它的图片

在此输入图片描述

我试图制作一个介绍页面,当您单击“开始”按钮时,您将进入登录页面

登录后台代码:

`

package com.example.imtv;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class LoginActivity extends AppCompatActivity {

private EditText userEdt,passEdt;
private Button Loginbtn;



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

    initView();
}

private void initView(){
    userEdt=findViewById(R.id.editTextText);
    passEdt=findViewById(R.id.editTextPassword);
    Loginbtn=findViewById(R.id.Loginbtn);

    Loginbtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (userEdt.getText().toString().isEmpty() || passEdt.getText().toString().isEmpty()){
                Toast.makeText(LoginActivity.this,"Please fill your username and password" , Toast.LENGTH_SHORT).show();
            }else if (userEdt.getText().toString().equals("test") && passEdt.getText().toString().equals("test")){
                startActivity(new Intent(LoginActivity.this,MainActivity.class));

            }else{
                Toast.makeText(LoginActivity.this, "Your username or password is not correct" , Toast.LENGTH_SHORT).show();
            }
        }
    });
}
}
`

登录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"
android:background="@color/main_color"
tools:context=".LoginActivity"
                                    

>

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:id="@+id/textView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Login"
            android:textSize="50sp"
            android:textColor="@color/white"
            android:layout_marginTop="128dp"
            android:layout_marginStart="32dp"
            android:textStyle="bold"
            />

        <EditText
            android:id="@+id/editTextText"
            android:layout_width="match_parent"
            android:layout_height="46dp"
            android:layout_marginStart="32dp"
            android:layout_marginTop="128dp"
            android:layout_marginEnd="32dp"
            android:background="@drawable/edittext_background"
            android:ems="10"
            android:hint="Username"
            android:inputType="text"
            android:textAlignment="center"
            android:textColor="@color/white"
            android:textColorHint="@color/white"

            />

        <EditText
            android:id="@+id/editTextPassword"
            android:layout_width="match_parent"
            android:layout_height="46dp"
            android:layout_marginStart="32dp"
            android:layout_marginTop="32dp"
            android:layout_marginEnd="32dp"
            android:background="@drawable/edittext_background"
            android:ems="10"
            android:hint="Password"
            android:inputType="textPassword"
            android:textAlignment="center"
            android:textColor="@color/white"
            android:textColorHint="@color/white"

            />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Forget your password?"
            android:textAlignment="center"
            android:textColor="@color/white"
            android:layout_marginTop="10dp"
            android:textSize="16dp"
            />

        <androidx.appcompat.widget.AppCompatButton
            android:id="@+id/Loginbtn"
            style="@android:style/Widget.Button"
            android:layout_marginTop="64dp"
            android:layout_marginStart="32dp"
            android:layout_marginEnd="32dp"
            android:background="@drawable/orange_button_background"
            android:textSize="18sp"
            android:textStyle="bold"
            android:textColor="@color/white"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Login" />

        <TextView
            android:id="@+id/textView5"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Don't have an account?"
            android:textColor="@color/white"
            android:textAlignment="center"
            android:textSize="16sp"
            android:layout_marginTop="10dp"/>

        <TextView
            android:id="@+id/textView7"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Register Now"
            android:textColor="@color/white"
            android:textSize="14sp"
            android:textAlignment="center"
            android:layout_marginTop="5dp"
            android:textStyle="bold"
            />
        "
            />


    </LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>`

后端代码介绍

 `




package com.example.imtv;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class IntroActivity extends AppCompatActivity {

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

    Button getinBtn=findViewById(R.id.getInbtn);
    getinBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(IntroActivity.this, LoginActivity.class));
        }
    });
}
}`

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=".IntroActivity"
android:background="@color/main_color"

                                       >

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <ImageView
                android:id="@+id/imageView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/intro_pic"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.0" />

            <ImageView
                android:id="@+id/imageView3"
                android:layout_width="match_parent"
                android:layout_height="550dp"
                android:src="@drawable/gradient_background"
                app:layout_constraintBottom_toBottomOf="@+id/imageView"
                tools:layout_editor_absoluteX="16dp" />

        </androidx.constraintlayout.widget.ConstraintLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:layout_marginTop="8dp"
            android:layout_marginStart="12dp"
            android:layout_marginEnd="24dp"
            >

            <TextView
                android:id="@+id/textView2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="NO MORE TIME TO WASTE"
                android:textColor="@color/white"
                android:textSize="27sp" />

            <TextView
                android:id="@+id/textView3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="15sp"
                android:text="Find the best movie to watch right now"
                android:textColor="@color/Orange"
                />

            <androidx.appcompat.widget.AppCompatButton
                android:id="@+id/getInbtn"
                style="@android:style/Widget.Button"
                android:layout_marginTop="8dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Get Started"
                android:textColor="@color/white"
                android:background="@drawable/orange_button_background"
                android:textSize="18sp"
                />


        </LinearLayout>

    </LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>`
java android kotlin
2个回答
0
投票

所有活动都应该在

androidmanifest.xml
文件中声明,从错误消息来看你还没有添加 LoginActivity。查看 android 文档 了解如何声明活动。

相关问题:如何正确添加Activity到manifest.xml?


0
投票

您尚未在清单中将包名称声明为 com.example.imtv 和活动名称。所以android会从com.example.imtv中搜索它。但是您的活动驻留在 LoginActivity 中。因此,请将活动名称指定为 .LoginActivity 或完整路径,如下所示在清单中:

<activity
                android:name="com.example.imtv.LoginActivity">

</activity>

© www.soinside.com 2019 - 2024. All rights reserved.