Android开发:创建空Activity后Manifest报错,引用类未找到求助
解决Manifest中Activity类找不到的错误
错误提示“Class referenced in the manifest, ... was not found in the project or the libraries”的核心原因是Manifest中声明的Activity类在项目中实际不存在。你提到仅创建了空Activity,但Manifest里列出了.WelcomeSecondActivity、.WelcomeFirstActivity等多个未创建的Activity,同时错误提示里的HomeActivity也属于类似情况——要么是Manifest中有残留声明,要么是拼写错误。
解决方案
- 删除或补全Activity声明:
- 若暂未计划创建这些Activity,直接删除Manifest中对应的
<activity>条目,只保留你已经创建的Activity(比如.Welcome.SplashScreenActivity,需确保这个类确实存在于com.example.bachelorstiffun.Welcome包下)。 - 若需要这些Activity,就在项目中创建对应的类,确保类的包名和Manifest中的声明匹配。比如创建
WelcomeSecondActivity时,包名要为com.example.bachelorstiffun(对应Manifest中的.WelcomeSecondActivity)。
- 若暂未计划创建这些Activity,直接删除Manifest中对应的
- 清理残留错误声明:检查Manifest中是否有
HomeActivity的遗漏声明,若有则删除或创建对应的类。 - 同步项目:修改完成后,点击Android Studio右上角的
Sync Project with Gradle Files按钮,让项目重新同步配置。 - 清除缓存(必要时):如果报错仍未消失,执行
File > Invalidate Caches... > Invalidate and Restart,清除IDE缓存后重启。
修改后的Manifest示例(仅保留已存在的Activity)
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.example.bachelorstiffun"> <application android:allowBackup="true" android:dataExtractionRules="@xml/data_extraction_rules" android:fullBackupContent="@xml/backup_rules" android:icon="@drawable/logo" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.BachelorsTiffun" tools:targetApi="31"> <activity android:name=".Welcome.SplashScreenActivity" android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!-- 仅保留已创建的Activity,未创建的暂时删除 --> </application> </manifest>
内容的提问来源于stack exchange,提问作者Shubham Singh
相关产品推荐
相关产品推荐

