问题描述
我有一个包含多个包的 android 项目.在这种情况下,包的结构是 com.WAPP.SetLocation 是包含我要运行的活动的包.
I have an android project with several packages. The structure of the packages in this case is com.WAPP.SetLocation is the package that contains the activity I want to run.
在我的清单中,com.WAPP 被视为基础包:
In my manifest, com.WAPP is considered the base package:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.WAPP"
android:versionCode="1"
android:versionName="1.0">
我的活动在清单中声明为:
My activities are declared in my manifest as:
<activity android:name=".mainScreenActivity"></activity>
<activity android:name=".SetLocation.setLocationActivity"></activity>
mainScreen 活动显示正常,因为它位于 com.WAPP 包内.但是当我尝试运行 setLocationActivity 时,我得到了无法找到显式类的错误.这是我如何获得意图参数:
The mainScreen activity displays fine, since it is inside the com.WAPP package. But when I try to run the setLocationActivity, I get the unable to find explicit class error. Here is how I have the intent parameters:
Intent i = new Intent();
i.setClassName("com.WAPP.SetLocation",
"com.WAPP.SetLocation.setLocationActivity");
startActivity(i);
推荐答案
第一个参数是应用程序包不是活动所在的包.
The first parameter is application package not the package where the activity is.
您可以像这样调用 Activity.
You can invoke the Activity like this.
Intent i = new Intent();
i.setClassName("com.WAPP",
"com.WAPP.SetLocation.setLocationActivity");
startActivity(i);
最好是因为 SYLARRR 建议让 Android 自动为您解决这个问题.因此调用为..
It is preferred as SYLARRR suggested to have Android automatically figure that out for you. Hence the call as..
startActivity(new Intent(this, setLocationActivity.class));
根据 Java 标准,建议将包名称全部小写,并将类名称设为 CamelCased.
It's recommended per java standards to have the package name all lower-cased and the class name as CamelCased.
这篇关于Android 错误“无法找到显式活动类"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!