我一直使用的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>
我可以保證,在您發佈一些你會得到沒有答案碼。 – Peaches491
查找崩潰的最佳方法是檢查LogCat。那基本上是androids系統日誌。你可以在'SDK/tools'文件夾的ddms應用程序中找到它,或者通過'Window-> Add view-> other-> LogCat'在eclipse中找到它。應該有一個例外(用標籤AndroidRuntime以紅色打印)。收到後,請將其張貼並添加相關代碼。 – 2011-08-15 18:54:30
我的問題的答案將爲您解答這個問題http://stackoverflow.com/questions/2209406/issues-with-android-tabhost-example – KevinDTimm