【问题标题】:Android: Activity not found exceptionAndroid:未找到活动异常
【发布时间】:2011-09-17 17:19:52
【问题描述】:

我在安卓系统中工作。我想制作 TabHost 和 Tab 小部件。这是我的清单:-

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.pericent"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
       <activity android:name=".HelloTabWidget" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar" >
          <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            </activity>
             <Acivity android:name=".AlbumsActivity" android:label="@string/app_name" />
        <activity android:name=".ArtistsActivity" android:label="@string/app_name" />

         <Acivity android:name=".SongsActivity" android:label="@string/app_name" />
    </application>
</manifest> 

这是我的 HelloTabWidget.java 包com.pericent;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.widget.TabHost;

public class HelloTabWidget extends TabActivity  {

    private String TAG="HelloTabWidget";

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Resources res = getResources(); // Resource object to get Drawables
        TabHost tabHost = getTabHost();  // The activity TabHost
        TabHost.TabSpec spec;  // Resusable TabSpec for each tab
        Intent intent1;  // Reusable Intent for each tab
        Intent intent2;
        Intent intent3;

        intent2 = new Intent().setClass(this, AlbumsActivity.class);
        Log.v(TAG,"---album activity is called---");
        spec = tabHost.newTabSpec("albums").setIndicator("Albums",res.getDrawable(R.drawable.ic_tab_albums)).setContent(intent2);
        tabHost.addTab(spec);

        // Create an Intent to launch an Activity for the tab (to be reused)
                intent1 = new Intent().setClass(this, ArtistsActivity.class);
        Log.v(TAG,"---artist activity is called---");
        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("artists").setIndicator("Artists",res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent1);
        tabHost.addTab(spec);

        // Do the same for the other tabs

     }

}

每当我运行这个项目时,这都会创建一个错误“无法启动活动 ComponentInfo{com.pericent/com.pericent.HelloTabWidget}:android.content.ActivityNotFoundException:无法找到显式活动类 {com.pericent /com.pericent.AlbumsActivity};您是否在 AndroidManifest.xml 中声明了此活动?"

但是如你所见,我在清单文件中声明了这个类。请检查这个并帮助找出我所做的错误。 提前谢谢你。

【问题讨论】:

  • 您的清单中有拼写错误.. 缺少某些部分。 &lt;Acivity。尝试一次干净的构建。

标签: android


【解决方案1】:

用您的清单文件替换此代码并清理项目然后RUN

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.pericent"
          android:versionCode="1"
          android:versionName="1.0">
        <application android:icon="@drawable/icon" android:label="@string/app_name">
           <activity android:name=".HelloTabWidget" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar" >
              <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
                </activity>
                 <acivity android:name=".AlbumsActivity" android:label="@string/app_name" />
            <activity android:name=".ArtistsActivity" android:label="@string/app_name" />

             <acivity android:name=".SongsActivity" android:label="@string/app_name" />
        </application>
</manifest> 

我认为您的标签名称“Activity”无法识别,所以我将其命名为“activity

【讨论】:

  • “活动”应该是“活动”
【解决方案2】:

我认为你的标签有问题

<Acivity android:name=".AlbumsActivity" android:label="@string/app_name" />

从活动中删除大写使用小“a”

【讨论】:

    猜你喜欢
    • 2023-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多