【发布时间】:2022-05-16 15:23:10
【问题描述】:
当我在 Android Studio 3.3 中创建一个新项目时,它会在 Run -> Edit Configurations 处显示错误提示
未找到默认活动。
<?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"
说
未解析的类 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.xml 、 ic_launcher_background.xml 和 ic_launcher_foreground.xml 格式不正确,看起来像这样 -
f
isInitialized
kotlin
Boolean
reflect
KProperty0
SinceKotlin
version
1.2
internal
InlineOnly0
4" 8�H PX�� (� �
我尝试Clean and Rebuild 项目,它给出了一个错误提示
colors.xml 格式不正确。
我尝试了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-
一年后我正在查看此内容,我很高兴它帮助了很多人。事实证明,这个问题可能由于各种问题而出现,并且没有一个完美的答案。因此,请检查所有答案,如果您遇到同样的问题,看看是否有适合您的方法:)
【问题讨论】:
-
您当前的项目文件已损坏,我认为您应该创建一个新项目并尝试。
-
我多次尝试创建一个新项目。文件已损坏,我每次都收到相同的错误。
-
那么您的 Android Studio 本身可能已损坏。您可能需要对其进行全新安装
-
然后将您的 android studio 恢复到以前的版本,即 3.2.1 或按照@Andreas 的建议重新安装 studio
-
@KaranHarshWardhan ,我在 3.2.1 中遇到了一些问题,gradle build 遇到了一些问题。我发现升级 Android Studio 作为解决方案,我的问题得到了解决。然后,一天后,这个问题开始了,但正如编辑中所建议的,Andreas 的解决方案奏效了
标签: android android-studio android-studio-3.3