android - 未找到默认 Activity - Android Studio 3.3 中的错误

标签 android android-studio android-studio-3.3

当我在 Android Studio 3.3 中创建一个新项目时,它在 Run -> Edit Configurations 处显示错误

default activity is not found.

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        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"/>

</android.support.constraint.ConstraintLayout>

这是我的activity_main.xml 文件。显示行错误

tools:context=".MainActivity"

Unresolved Class MainActivity

这是我的 AndroidManifest.xml 文件 - 一切似乎都在这里 -

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

<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>

colors.xmlic_launcher_background.xmlic_launcher_foreground.xml 文件格式不正确,看起来像这样 -

        f

        isInitialized
        kotlin
        Boolean
        reflect

        KProperty0
        SinceKotlin
        version
        1.2
        internal

        InlineOnly0






             4"  8�H PX��     (�    �

我尝试Clean and Rebuild 项目,但出现错误提示

colors.xml is not formed properly.

我尝试了 File -> Invalidate Caches/Restart,但它仍然显示相同的错误。

此问题是在将 Android Studio 3.2.1 更新到 Android Studio 3.3 一天后出现的。第一天一切正常,但当我在第二天尝试运行应用程序时,它开始显示此错误,提示 Default Activity not found

有没有办法解决这个问题并继续使用 Android Studio 3.3 版?

编辑 -

耶!正如@Andreas 所建议的那样,我的 Android Studio 本身可能已损坏,并且在卸载并重新安装相同版本后一切正常(我什至没有恢复到旧版本)。应检查此问题是否会在几天内再次出现。

编辑 2-

我在一年后查看此内容,我很高兴它帮助了很多人。原来这个问题可能由于各种问题而出现,并且没有一个完美的答案。因此,如果您遇到同样的问题,请检查所有答案,看看是否有适合您的方法:)

最佳答案

经过大量搜索后,这对我有用,

转到编辑配置 -> 选择您的应用程序模块 -> 在启动选项下 -> 从启动下拉列表中选择无。

(引用图片以获得更好的引用) enter image description here

关于android - 未找到默认 Activity - Android Studio 3.3 中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54319860/

相关文章:

android - 如何获取我的 Activity 上下文?

java - 了解 Android 上的多点触控?

Android 处理程序 bufferedreader.read() 在接收数据时关闭应用程序

Android Studio 只为多模块项目中没有模块依赖的模块生成 R 文件

android-layout - Android studio 3.3 Go to Declaration 不起作用

android - Jetpack 撰写 : Custom VectorAsset Icon object similar to built-in `Icons.Default`

java - Android 应用程序在 android studio 中点击时没有响应?

android - Android Studio 中的所有 Activity 和布局都已损坏

android - 安装失败,因为 APK 未签名

android-studio - Android Studio 3.3,布局预览、放大、缩小和缩放以适合屏幕按钮不起作用