2012-06-02 45 views
0

致命異常 E/AndroidRuntime(535):java.lang.RuntimeException:無法實例化活動組件.This.Calculator.ThisBatteryCalculatorActivity我不斷收到錯誤致命異常。無法實例化活動

我只是按照Android開發者的標籤視圖的教程,我想我認爲我跟着它的話......但似乎我沒有。有人可以幫幫我嗎? 我使用eclipse btw。

這裏是我的代碼:

爲ThisBatteryCalculator

package com.This.Calculator; 

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



@SuppressWarnings("deprecation") 
public class ThisBatteryCalculator extends TabActivity { 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    Resources res = getResources(); // Resource object to get Durables 
    TabHost tabHost = getTabHost(); // The activity TabHost 
    TabHost.TabSpec spec; // Reusable TabSpec for each tab 
    Intent intent; // Reusable Intent for each tab 

    // Create an Intent to launch an Activity for the tab (to be reused) 
    intent = new Intent().setClass(this, ArtistsActivity.class); 

    // 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(intent); 
    tabHost.addTab(spec); 

    // Do the same for the other tabs 
    intent = new Intent().setClass(this, AlbumsActivity.class); 
    spec = tabHost.newTabSpec("albums").setIndicator("Albums", 
         res.getDrawable(R.drawable.ic_tab_albums)) 
        .setContent(intent); 
    tabHost.addTab(spec); 

    intent = new Intent().setClass(this, SongActivity.class); 
    spec = tabHost.newTabSpec("songs").setIndicator("Songs", 
         res.getDrawable(R.drawable.ic_tab_songs)) 
        .setContent(intent); 
    tabHost.addTab(spec); 

    tabHost.setCurrentTab(2); 
} 
} 

我的清單:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.This.Calculator" 
android:versionCode="1" 
android:versionName="1.0" > 

<uses-sdk android:minSdkVersion="15" /> 

<application 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" > 
    <activity 
     android:name=".ThisBatteryCalculatorActivity"   
     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> 
     <activity android:name=".ArtistsActivity" 
      android:label="@string/app_name" 
      android:theme="@android:style/Theme.NoTitleBar"> 
</activity> 

<activity android:name=".SongActivity" 
      android:label="@string/app_name" 
      android:theme="@android:style/Theme.NoTitleBar"> 
</activity> 

<activity android:name=".AlbumsActivity" 
      android:label="@string/app_name" 
      android:theme="@android:style/Theme.NoTitleBar"> 
</activity> 

</application> 



</manifest> 

終於爲我的main.xml:

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@android:id/tabhost" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="5dp"> 
    <TabWidget 
     android:id="@android:id/tabs" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 
    <FrameLayout 
     android:id="@android:id/tabcontent" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:padding="5dp" /> 
</LinearLayout> 
</TabHost> 

任何幫助會b非常感謝!謝謝!

回答

0

在您的清單中,您有ThisBatteryCalculatorActivity作爲活動類的名稱。

在源代碼中,您有ThisBatteryCalculator作爲活動類的名稱。

ThisBatteryCalculatorActivityThisBatteryCalculator是不一樣的。他們需要是一樣的。你選擇哪個取決於你。請將類重命名爲ThisBatteryCalculatorActivity或將您的清單重新命名爲ThisBatteryCalculator

+0

非常感謝!一個簡單的問題:/我總是錯過細節... –

相關問題