android.content.ActivityNotFoundException,无法启动活动



我的应用程序清单有问题。点击主活动上的按钮,我想启动另一个活动,所以我使用了这个函数:

public void startDatacenters() {
    Intent intent = new Intent(context, Datacenters.class);
    activity.startActivity(intent);}

Datacenters.class的包是com.eco4cloud.activities.Datacenters

我的manifest是这样的

<?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): closing down VM .日志示例05-24 18:01:32.622: W/dalvikvm(15404): threadid=1:线程退出未捕获异常(group=0x40a441f8)05-24 18:01:32.632: E/AndroidRuntime(15404): FATAL EXCEPTION: main05-24 18:01:32.632: E/AndroidRuntime (15404): java.lang.RuntimeException: ComponentInfo {com.eco4cloud/com.eco4cloud.activities无法开始活动。android.content.ActivityNotFoundException:无法找到显式的活动类{com.eco4cloud/com.eco4cloud.activities. datacenters};你有没有在你的AndroidManifest.xml中声明这个活动?05-24 18:01:32.632: E/AndroidRuntime(15404): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2079)05-24 18:01:32.632: E/AndroidRuntime(15404): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)05-24 18:01:32.632: E/AndroidRuntime(15404): at android.app.ActivityThread.access$600(ActivityThread.java:132)05-24 18:01:32.632: E/AndroidRuntime(15404): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1157)05-24 18:01:32.632: E/AndroidRuntime(15404): at android.os.Handler.dispatchMessage(Handler.java:99)05-24 18:01:32.632: E/AndroidRuntime(15404): at android.os. loop(loop .java:137)05-24 18:01:32.632: E/AndroidRuntime(15404): at android.app.ActivityThread.main(ActivityThread.java:4575)05-24 18:01:32.632: E/AndroidRuntime(15404): at java.lang.reflect.Method。invokeNative(本地方法)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$ methodandargscaler .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. native . art。主要(本地方法)05-24 18:01:32.632: E/AndroidRuntime(15404): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.eco4cloud/com.eco4cloud.activities. datacenters};你有没有在你的AndroidManifest.xml中声明这个活动?05-24 18:01:32.632: E/AndroidRuntime(15404): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1508)05-24 18:01:32.632: E/AndroidRuntime(15404): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)05-24 18:01:32.632: E/AndroidRuntime(15404): at android.app.Activity.startActivityForResult(Activity.java:3190)05-24 18:01:32.632: E/AndroidRuntime(15404): at 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): at android.app.Activity.performCreate(Activity.java:4465)05-24 18:01:32.632: E/AndroidRuntime(15404): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)05-24 18:01:32.632: E/AndroidRuntime(15404): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2033)05-24 18:01:32.632: E/AndroidRuntime(15404):…11个

有人能帮帮我吗??我不知道问题是包名还是其他东西:(

我不知道你想做什么。

但有几个建议可以尝试。

    package="com.eco4cloud.activities" 
    // make sure package name is right.
    // probably it should be as above. 

如上所述的包名

既然你有明确的意图,你就不需要意图过滤器

      // 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>
如果包= " 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 
    }

尝试在应用程序清单"com.eco4cloud.activities "中提供活动的完全限定名称。"。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="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>

相关内容

  • 没有找到相关文章

最新更新