Java 如何解决;未找到默认活动";安卓工作室?

Java 如何解决;未找到默认活动";安卓工作室?,java,android,android-studio,Java,Android,Android Studio,背景 昨天刚在安卓Studio(最新版本,4.0)上启动了一个空项目并保存了该文件,今天早上我打开了它,却遇到了一个新的NDK安装和一些更新。现在,我无法运行应用程序,因为我得到了“运行'java'时出错,未找到默认活动”的响应。很自然,我转向StackOverflow,发现还有其他人面临同样的问题。我遵循了其中一些原则,例如: (1) 使缓存无效并重新启动 (2) 删除/缓存文件夹 无论我遵循这些指令中的哪一条,我都注意到在Make Project图标旁边的android符号“Open‘Edi

背景

昨天刚在安卓Studio(最新版本,4.0)上启动了一个空项目并保存了该文件,今天早上我打开了它,却遇到了一个新的NDK安装和一些更新。现在,我无法运行应用程序,因为我得到了“运行'java'时出错,未找到默认活动”的响应。很自然,我转向StackOverflow,发现还有其他人面临同样的问题。我遵循了其中一些原则,例如:

(1) 使缓存无效并重新启动

(2) 删除/缓存文件夹

无论我遵循这些指令中的哪一条,我都注意到在Make Project图标旁边的android符号“Open‘Edit Run/Debug Configurations’dialog”后面有一个大的红色X。当我开始编辑配置,转到“启动选项”和“启动:默认活动”时,在“运行/调试配置”窗口的底部会立即出现一条警告,指出“未找到默认活动”。虽然我怀疑原因是因为任何文件,但它们就在这里

活动\u main.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=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.opencvproject">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>
AndroidManifest.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=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.opencvproject">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

我可以通过编辑配置>启动选项,将启动从默认活动更改为无,从而略过此错误。然而,虽然我能够在Android Studio中运行该项目,但应用程序不再像以前那样在我的设备上自动启动。