2011-08-15 38 views
1

我一直使用的Xcode過去那麼現在我想學習Android和我使用Eclipse這是爲什麼會崩潰?如何調試?

我跟着http://developer.android.com/resources/tutorials/views/hello-tabwidget.html列出的所有步驟,但是當我真正在我的LG革命運行的代碼( Froyo 2.2.1),我崩潰了。

我不知道如何調試,但我不知道爲什麼這甚至會崩潰。任何幫助,將不勝感激。

我用同樣的圖像對所有3個標籤(這就是我所做的唯一修改,但我不認爲它應該崩潰)

這裏是我的代碼

package com.oneorangetree.shit; 

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

public class HelloTabWidgetActivity extends TabActivity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     // Resource object to get drawable 
     Resources res = getResources(); 
     TabHost tabHost = getTabHost(); 
     TabHost.TabSpec spec; 
     Intent intent; 

     intent = new Intent().setClass(this, ArtistsActivity.class); 
     spec = tabHost.newTabSpec("artists").setIndicator("Artists", res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent); 
     tabHost.addTab(spec); 

     intent = new Intent().setClass(this, AlbumsActivity.class); 
     spec = tabHost.newTabSpec("albums").setIndicator("Albums", res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent); 
     tabHost.addTab(spec); 

     intent = new Intent().setClass(this, SongsActivity.class); 
     spec = tabHost.newTabSpec("songs").setIndicator("Songs", res.getDrawable(R.drawable.ic_tab_artists)).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.oneorangetree.shit" 
     android:versionCode="1" 
     android:versionName="1.0"> 
    <uses-sdk android:minSdkVersion="8" /> 

    <application android:icon="@drawable/icon" android:label="@string/app_name"> 
     <activity android:name=".HelloTabWidgetActivity" 
        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> 

    </application> 
</manifest> 
+3

我可以保證,在您發佈一些你會得到沒有答案碼。 – Peaches491

+2

查找崩潰的最佳方法是檢查LogCat。那基本上是androids系統日誌。你可以在'SDK/tools'文件夾的ddms應用程序中找到它,或者通過'Window-> Add view-> other-> LogCat'在eclipse中找到它。應該有一個例外(用標籤AndroidRuntime以紅色打印)。收到後,請將其張貼並添加相關代碼。 – 2011-08-15 18:54:30

+0

我的問題的答案將爲您解答這個問題http://stackoverflow.com/questions/2209406/issues-with-android-tabhost-example – KevinDTimm

回答

1

http://code.google.com/p/android/issues/detail?id=4183的信息和我原來的問題落實Ted的修正 - 下面是明顯的,但也有其他錯誤太:

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

狂猜:你是否將所有的活動添加到清單中?一個活動等於清單中提到的一個活動。

當您創建一個projet時,您的主要活動默認添加到此文件中,以便系統知道啓動您的主要活動是否正常。現在,每次你在你的項目中添加一個新的活動時間,你必須添加在清單本次活動:

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

如果不是,你點擊你的文件的左邊空白處添加一些破發點,然後單擊在調試按鈕上。最後,打開調試視圖,然後使用F8在中斷點之間導航。

希望它有幫助,一直在那裏:)。