Android 为什么在对存在于不同模块中的类调用Class.forName()时会出现ClassNotFoundException
所以我把一个活动移到了我们的第一个dynamicModule中。我尝试使用以下代码导航到该活动:Android 为什么在对存在于不同模块中的类调用Class.forName()时会出现ClassNotFoundException,android,android-module,Android,Android Module,所以我把一个活动移到了我们的第一个dynamicModule中。我尝试使用以下代码导航到该活动: private enum class ACTIVITIES(val location: String) { EXAMPLE_ACTIVITY("com.example.feature_member_home.ExampleActivity"),//com.example.feature_member_home REFERRAL_SELECTION_ACTIVITY("com.sofi
private enum class ACTIVITIES(val location: String) {
EXAMPLE_ACTIVITY("com.example.feature_member_home.ExampleActivity"),//com.example.feature_member_home
REFERRAL_SELECTION_ACTIVITY("com.sofi.mobile.feature_example.ReferralSelectionActivity")//com.sofi.mobile.feature_referrals.ReferralSelectionActivity
}
@Throws(LinkageError::class, ExceptionInInitializerError::class, ClassNotFoundException::class)
fun locateReferralSelectionActivity(context: Context): Intent {
try {
return Intent(context, Class.forName(ACTIVITIES.REFERRAL_SELECTION_ACTIVITY.location))
} catch (e: Exception) {
throw e
}
}
但是行Class.forName(ACTIVITIES.reflection\u SELECTION\u ACTIVITY.location)
在路径DexPathList上给出了一个错误ClassNotFoundException
你知道我做错了什么吗?在评论中,你是不是用
feature\u references
&feature\u example
?@NamNH不,我已经仔细检查了包名。嗯,因为我看到了com.sofi.mobile.feature\u示例.ReferralSelectionActivity
&您的评论//com.sofi.mobile.feature\u referrals.ReferralSelectionActivity
。在这种情况下,您可以尝试在应用程序build.gradle
文件中使缓存无效并重新启动android studio
或启用multiDexEnabled
。