按钮不可点击+点击时应用程序崩溃

这是崩溃错误 logcat,每次我在寄存器上计时时,应用程序都会崩溃。

我的模拟器是 AndroidQ 模拟器设备上的 2GB RAM。

2019-09-22 16:36:39.307 6454-6454/com.connex.connexsocial E/AndroidRuntime:致命异常:主进程:com.connex.connexsocial,PID:6454 android.content.ActivityNotFoundException:无法找到显式活动类{com.connex.connexsocial/com.connex.connexsocial.LoginActivity};您是否在 AndroidManifest.xml 中声明了此活动?在 android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1933) 在 android.app.Instrumentation.execStartActivity(Instrumentation.java:1616) 在 android.app.Activity.startActivityForResult(Activity.java:4487) 在 androidx.fragment。 app.FragmentActivity.startActivityForResult(FragmentActivity.java:676) 在 android.app.Activity.startActivityForResult(Activity.java:4445) 在 androidx.fragment。

这是我的主要活动

<?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="match_parent"

    android:layout_height="match_parent"

    android:background="#7ed957"

    android:padding="20dp"

    tools:contet=".MainActivity">


    <ImageView

        android:layout_height="match_parent"

        android:layout_width="match_parent"

        android:src="@drawable/logo1"

        android:layout_centerHorizontal="true"

        android:contentDescription="@string/todo" />


        <!--Button: Register-->

    <Button

        android:id="@+id/register_btn"

        android:text="@string/register"

        android:layout_above="@+id/login_btn"

        style="@style/Widget.AppCompat.Button.Colored"

        android:layout_width="match_parent"

        android:layout_height="wrap_content" />


</RelativeLayout>

每次我单击“登录”时都什么也不做,每次我单击“注册”时它都会崩溃。


蛊毒传说
浏览 78回答 2
2回答

杨魅力

您需要在清单文件中声明 LoginActivity,如 AndroidManifest.xml<activity android:name="com.connex.connexsocial.LoginActivity" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/>

qq_花开花谢_0

每当您的应用程序崩溃时,第一个调试步骤应该是检查您的 logcat,logcat 中总是有线索。如果您检查发布的日志,您将看到以下行:android.content.ActivityNotFoundException:无法找到显式活动类 {com.connex.connexsocial/com.connex.connexsocial.LoginActivity};您是否在 AndroidManifest.xml 中声明了此活动?从字面上看,这意味着您收到此错误是因为您尚未在清单中声明该活动。要解决此问题,只需将其粘贴到清单文件的应用程序元素中:<activity&nbsp;android:name="com.connex.connexsocial.LoginActivity"></activity>这种相同的调试模式几乎适用于所有崩溃事件。你总能从 logcat 中得到线索。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java