Java android选项卡布局错误
我正在尝试使标签布局。我正在使用教程代码(如下),但它不起作用。LogCat给出了以下错误: 04-19 19:02:16.297:错误/AndroidRuntime(455):java.lang.RuntimeException:无法启动活动组件信息{jusbrz.bakalauras/jusbrz.bakalauras.FilesTabsActivity}:java.lang.RuntimeException:您的内容必须有一个id属性为“android.R.id.TabHost”的TabHost 我在清单中添加了新的活动 XML: 那么问题出在哪里呢 已编辑Java android选项卡布局错误,java,android,tabs,Java,Android,Tabs,我正在尝试使标签布局。我正在使用教程代码(如下),但它不起作用。LogCat给出了以下错误: 04-19 19:02:16.297:错误/AndroidRuntime(455):java.lang.RuntimeException:无法启动活动组件信息{jusbrz.bakalauras/jusbrz.bakalauras.FilesTabsActivity}:java.lang.RuntimeException:您的内容必须有一个id属性为“android.R.id.TabHost”的TabH
import android.app.TabActivity;
import android.os.Bundle;
public class AllFilesTabActivity extends TabActivity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.all_files_tab_layout);
}
}
布局中缺少tabhost id。请将布局更新为:
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@android:id/tabhost">
如果要动态添加选项卡,请执行以下操作:
setContentView(R.layout.files_tabs_layout);
如果要使用
TabActivity
,则需要使用@android:id/tabhost
作为tabhost
的android值
浏览有关StackOverflow的其他几个问题,似乎执行“项目-->清理”并重新启动Eclipse也会有所帮助。这没有帮助。错误仍然存在up@LTnewbie:使用
Projects-->clean
清理项目我清理了项目。已重新启动AVD,但问题仍然存在。我使用的是2.2,也许这是个问题?@LTnewbie:2.2没问题,只要用正确的方式实现就行了。只需注释掉setContentView(R.layout.files\u tabs\u layout)代码>
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@android:id/tabhost">
TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);
TabSpec firstTabSpec = tabHost.newTabSpec("Visi");
firstTabSpec.setIndicator("Visi").setContent(new Intent(this,AllFilesTabActivity.class));
/** Add tabSpec to the TabHost to display. */
tabHost.addTab(firstTabSpec);
setContentView(R.layout.files_tabs_layout);