如何解决 Activity 未找到异常

How do I resolve Activity Not Found Exception

在我的 android 应用程序中,我在清单文件中添加了一个 activity MainActivity,导航到那个 activity 使用一个意向 activity not found error 问我是否已将它添加到清单

这是我的清单activity

        <activity
            android:name=".MainActivity"
            android:clearTaskOnLaunch="true"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:icon="@mipmap/ic_launcher"
            android:rotationAnimation="seamless"
            android:screenOrientation="portrait"
            android:theme="@style/Theme.AppCompat"
            tools:targetApi="O">

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


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

<!--            Register as a system camera app-->
            <intent-filter>
                <action android:name="android.media.action.IMAGE_CAPTURE" />
                <action android:name="android.media.action.STILL_IMAGE_CAMERA" />
                <action android:name="android.media.action.VIDEO_CAMERA" />

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

            <!-- App links for http/s -->
            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data android:scheme="http" />
                <data android:scheme="https" />
                <data android:host="example.android.com" />
                <data android:pathPattern="/camerax" />
            </intent-filter>

            <!-- Declare notch support -->
            <meta-data
                android:name="android.notch_support"
                android:value="true" />
        </activity>

这是日志

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.virtusync.scanningtool, PID: 28538
    android.content.ActivityNotFoundException: Unable to find explicit activity class {com.virtusync.scanningtool/com.android.example.cameraxbasic.MainActivityKt}; have you declared this activity in your AndroidManifest.xml?
        at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2005)
        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1673)
        at android.app.Activity.startActivityForResult(Activity.java:4586)
        at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:675)
        at android.app.Activity.startActivityForResult(Activity.java:4544)
        at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:662)
        at android.app.Activity.startActivity(Activity.java:4905)
        at android.app.Activity.startActivity(Activity.java:4873)
        at com.android.example.cameraxbasic.SelectOperation.onClick(SelectOperation.java:36)
        at android.view.View.performClick(View.java:7044)
        at android.view.View.performClickInternal(View.java:7017)
        at android.view.View.access00(View.java:784)
        at android.view.View$PerformClick.run(View.java:26596)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6819)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:497)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:912)

我已经做到了 还没有解决方案

您是否重命名了 activity? 错误消息显示 "MainActivityKt" 未找到,但清单文件中的 Activity 名为 "MainActivity".

重命名清单中的 activity 或 Java class。

错误消息说明了一切,

android.content.ActivityNotFoundException: Unable to find explicit activity class {com.virtusync.scanningtool/com.android.example.cameraxbasic.MainActivityKt}; have you declared this activity in your AndroidManifest.xml?

从你的清单上看,你没有。

声明的唯一 activity 是 MainActivity

<activity
     android:name=".MainActivity"
     ...

出现异常是因为在您的代码中您使用了名为 MainActivityKt 的 class。

可能是你拼错了那个名字,改正它。