我最近開始了Android開發,並且我已經知道Java。所以我在關於如何創建一個選項卡式佈局的Android開發網站上的 This教程。 即使我在教程和eclipse中的所有內容後都提示沒有錯誤,但是當我在froyo API 8級仿真器上運行應用程序時,應用程序崩潰。我的應用程序是建立以及對API級別8Android選項卡式佈局/視圖崩潰
什麼,我認爲可能會導致它: 1)我似乎已經在AndroidManifest.xml一條警告信息,我不明白,它強調了這一行:
<uses-sdk android:minSdkVersion="8" />
2)在教程中,他們使用5個選項卡創建了一個包含3個選項卡的頁面。也許這就是它??]
我的代碼:
主要活動:
package ent.com;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;
public class TestActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, Players.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("players").setIndicator("Players",
res.getDrawable(R.drawable.ic_tab_players))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, Staff.class);
spec = tabHost.newTabSpec("staff").setIndicator("Staff",
res.getDrawable(R.drawable.ic_tab_staff))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, League.class);
spec = tabHost.newTabSpec("league").setIndicator("League",
res.getDrawable(R.drawable.ic_tab_league))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Finance.class);
spec = tabHost.newTabSpec("finance").setIndicator("Finance",
res.getDrawable(R.drawable.ic_tab_finance))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Next.class);
spec = tabHost.newTabSpec("next").setIndicator("Next Game",
res.getDrawable(R.drawable.ic_tab_next))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(2);
}
}
我的AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ent.com"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".TestActivity"
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>
感謝您的幫助!
添加堆棧跟蹤,請 – 2012-04-10 14:39:03