2011-09-17 89 views
0

我正在android中工作。我想製作TabHost和Tab小部件。這是我的清單: -Android:未找到活動例外

<?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中聲明瞭這個活動?

但是正如你所看到的,我在manifest文件中聲明瞭這個類。請檢查這一點,並幫助找出我所做的錯誤。 預先感謝您。

+5

您的清單中存在拼寫錯誤,部分文件丟失。 ' Ronnie

回答

1

我認爲問題是與你的標籤

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

取下蓋子從活動中使用小「一」

+0

感謝pushpendra acha huya解決kaam aaya :) –

+0

hanji bhaiya ... –

3

與清單文件替換這個代碼,並清理項目,然後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

+4

「活力」應該是「活動」 – pahan