タブ付きアプリケーションを作成しようとしていますが、アプリケーションを実行しようとすると問題が発生し、メインクラスがTabActivityを拡張します。メインクラスコードは次のとおりです。
package org.practical.newsupdate;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class NewsPage extends TabActivity{
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.newspage);
TabHost host = (TabHost) findViewById(R.id.tabhost);
host.setup();
new Intent().setClass(this, LocalNews.class);
TabSpec localTab = host.newTabSpec("Local");
localTab.setIndicator(getResources().getString(R.string.local),
getResources().getDrawable(android.R.drawable.star_on));
localTab.setContent(R.id.local_tab);
host.addTab(localTab);
new Intent().setClass(this, ForeignNews.class);
TabSpec foreignTab = host.newTabSpec("Foreign");
foreignTab.setIndicator(getResources().getString(R.string.foreign),
getResources().getDrawable(android.R.drawable.star_on));
foreignTab.setContent(R.id.foreign_tab);
host.addTab(foreignTab);
host.setCurrentTabByTag("Local");
}
}
XMLは次のとおりです。
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/newsimages" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="@drawable/newsimages" />
<TextView
android:id="@+id/newspage_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/menu_newspage" />
</RelativeLayout>
<TabHost
android:id="@+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/local_tab"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</LinearLayout>
<LinearLayout
android:id="@+id/foreign_tab"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
log catには、次のエラーが表示されます。
12-25 18:11:24.846:E / AndroidRuntime(569):致命的な例外:メイン12-25 18:11:24.846:E / AndroidRuntime(569):java.lang.RuntimeException:アクティビティComponentInfo{orgを開始できません。 actual.newsupdate / org.practical.newsupdate.NewsPage}:java.lang.RuntimeException:コンテンツにはid属性が「android.R.id.tabhost」であるTabHostが必要です12-25 18:11:24.846:E / AndroidRuntime (569):android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)12-25 18:11:24.846:E / AndroidRuntime(569):android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980) 12-25 18:11:24.846:E / AndroidRuntime(569):android.app.ActivityThread.access $ 600(ActivityThread.java:122)12-25 18:11:24.846:E / AndroidRuntime(569):android .app.ActivityThread $ H.handleMessage(ActivityThread.java:1146)12-25 18:11:24.846:E / AndroidRuntime(569):android.os.Handler.dispatchMessage(Handler.java:99)12-25 18:11:24.846:E / AndroidRuntime(569):android.os.Looper.loop(Looper.java) :137)12-25 18:11:24.846:E / AndroidRuntime(569):android.app.ActivityThread.main(ActivityThread.java:4340)12-25 18:11:24.846:E / AndroidRuntime(569): at java.lang.reflect.Method.invokeNative(Native Method)12-25 18:11:24.846:E / AndroidRuntime(569):at java.lang.reflect.Method.invoke(Method.java:511)12-25 18:11:24.846:E / AndroidRuntime(569):com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:784)12-25 18:11:24.846:E / AndroidRuntime(569): com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)12-25 18:11:24.846:E / AndroidRuntime(569):dalvik.system.NativeStart.main(ネイティブメソッド)12-25 18:11:24.846:E / AndroidRuntime(569):原因:java.lang。RuntimeException:コンテンツにはid属性が'android.R.id.tabhost'であるTabHostが必要です12-2518:11:24.846:E / AndroidRuntime(569):android.app.TabActivity.onContentChanged(TabActivity.java: 131)12-25 18:11:24.846:E / AndroidRuntime(569):com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:254)12-25 18:11:24.846:E / AndroidRuntime(569):android.app.Activity.setContentView(Activity.java:1835)12-25 18:11:24.846:E / AndroidRuntime(569):org.practical.newsupdate.NewsPage.onCreate(NewsPage.java) :13)12-25 18:11:24.846:E / AndroidRuntime(569):android.app.Activity.performCreate(Activity.java:4465)12-25 18:11:24.846:E / AndroidRuntime(569): android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)12-25 18:11:24.846:E / AndroidRuntime(569):android.app.ActivityThreadで。PerformLaunchActivity(ActivityThread.java:1919)12-25 18:11:24.846:E / AndroidRuntime(569):... 11 more
表示されているエラーは、アプリケーションが突然動作を停止したことです。誰か助けてくれませんか?
助けてくれてありがとう