我的应用程序清单有问题。 单击主要活动上的按钮我想启动另一个活动,所以我使用了这个功能:
public void startDatacenters() {
Intent intent = new Intent(context, Datacenters.class);
activity.startActivity(intent);}
Datacenters.class包是com.eco4cloud.activities.Datacenters
所以我的表现就是这样:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.eco4cloud"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".activities.Main"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activities.Datacenters"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.eco4cloud.activities.DATACENTERS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Android给了我这个错误,我不知道为什么:(
有人可以帮帮我吗? 我不知道问题是关于包名还是其他东西:(05-24 18:01:32.622:D / AndroidRuntime(15404):关闭VM 05-24 18:01:32.622:W / dalvikvm(15404):threadid = 1:线程退出,未捕获异常(group = 0x40a441f8) 05-24 18:01:32.632:E / AndroidRuntime(15404):致命异常:主要 05-24 18:01:32.632:E / AndroidRuntime(15404):java.lang.RuntimeException:无法启动活动ComponentInfo {com.eco4cloud / com.eco4cloud.activities.Main}:android.content.ActivityNotFoundException:无法找到显式活动类{com.eco4cloud / com.eco4cloud.activities.Datacenters};你有没有在AndroidManifest.xml中声明这个活动? 05-24 18:01:32.632:E / AndroidRuntime(15404):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2079) 05-24 18:01:32.632:E / AndroidRuntime(15404):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104) 05-24 18:01:32.632:E / AndroidRuntime(15404):在android.app.ActivityThread.access $ 600(ActivityThread.java:132) 05-24 18:01:32.632:E / AndroidRuntime(15404):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1157) 05-24 18:01:32.632:E / AndroidRuntime(15404):在android.os.Handler.dispatchMessage(Handler.java:99) 05-24 18:01:32.632:E / AndroidRuntime(15404):在android.os.Looper.loop(Looper.java:137) 05-24 18:01:32.632:E / AndroidRuntime(15404):在android.app.ActivityThread.main(ActivityThread.java:4575) 05-24 18:01:32.632:E / AndroidRuntime(15404):at java.lang.reflect.Method.invokeNative(Native Method) 05-24 18:01:32.632:E / AndroidRuntime(15404):at java.lang.reflect.Method.invoke(Method.java:511) 05-24 18:01:32.632:E / AndroidRuntime(15404):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:789) 05-24 18:01:32.632:E / AndroidRuntime(15404):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556) 05-24 18:01:32.632:E / AndroidRuntime(15404):at dalvik.system.NativeStart.main(Native Method) 05-24 18:01:32.632:E / AndroidRuntime(15404):引起:android.content.ActivityNotFoundException:无法找到显式活动类{com.eco4cloud / com.eco4cloud.activities.Datacenters};你有没有在AndroidManifest.xml中声明这个活动? 05-24 18:01:32.632:E / AndroidRuntime(15404):在android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1508) 05-24 18:01:32.632:E / AndroidRuntime(15404):在android.app.Instrumentation.execStartActivity(Instrumentation.java:1384) 05-24 18:01:32.632:E / AndroidRuntime(15404):在android.app.Activity.startActivityForResult(Activity.java:3190) 05-24 18:01:32.632:E / AndroidRuntime(15404):在android.app.Activity.startActivity(Activity.java:3297) 05-24 18:01:32.632:E / AndroidRuntime(15404):at com.eco4cloud.controllers.MainController.startDatacenters(MainController.java:46) 05-24 18:01:32.632:E / AndroidRuntime(15404):at com.eco4cloud.activities.Main.verifyAndSignIn(Main.java:117) 05-24 18:01:32.632:E / AndroidRuntime(15404):at com.eco4cloud.activities.Main.onCreate(Main.java:53) 05-24 18:01:32.632:E / AndroidRuntime(15404):在android.app.Activity.performCreate(Activity.java:4465) 05-24 18:01:32.632:E / AndroidRuntime(15404):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 05-24 18:01:32.632:E / AndroidRuntime(15404):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2033) 05-24 18:01:32.632:E / AndroidRuntime(15404):... 11 more
答案 0 :(得分:3)
我不确定你要做什么。
但要提出几点建议。
package="com.eco4cloud.activities"
// make sure package name is right.
// probably it should be as above.
如上所述提及包名称
由于您有明确的意图,因此不需要使用intent-filter
// use this assuming Datacenters is in package com.eco4cloud.activities
// also assuming package="com.eco4cloud.activities"
<activity
android:name=".Datacenters"
android:label="@string/app_name" >
</activity>
如果package =“com.eco4cloud”,请尝试以下
<activity
android:name="com.eco4cloud.activities.Datacenters"
android:label="@string/app_name" >
</activity>
如果您要在非活动类中开始活动
public void startDatacenters() {
Intent intent = new Intent(context, Datacenters.class);
// assuming context is the activity content
context.startActivity(intent);
//in your case you have activity.startActivity(intent)
// not sure what activity is
}
答案 1 :(得分:0)
尝试在应用清单“com.eco4cloud.activities.Datacenters”中提供活动的完全限定名称,而不仅仅是“.activities.Datacenters”
答案 2 :(得分:0)
你可以这样使用
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.eco4cloud"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.eco4cloud.activities.Main"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.eco4cloud.activities.Datacenters"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.eco4cloud.activities.DATACENTERS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>