【发布时间】:2012-01-27 06:19:05
【问题描述】:
我对 Android 项目非常陌生。只是我尝试在 Android 中使用TabHost 控制器。我从这个链接得到了一个代码,coderzheaven.com。但是,在这段代码中,我收到了一个错误Syntax error, insert ";" to complete。这是我的代码,
package tab.fragment;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class TabBarSample extends TabActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);
TabSpec firstTabSpec = tabHost.newTabSpec("tab_id1");
TabSpec secondTabSpec = tabHost.newTabSpec("tab_id2");
TabSpec thirdTabSpec = tabHost.newTabSpec("tab_id3");
firstTabSpec.setIndicator("Time").setContent(new Intent(this,Time.class));
secondTabSpec.setIndicator("Date").setContent(new Intent(this,Date.class));
thirdTabSpec.setIndicator("Option").setContent(new Intent(this,Option.class));
tabHost.addTab(firstTabSpec);
tabHost.addTab(secondTabSpec);
tabHost.addTab(thirdTabSpec); //Here the error occuring..
}
}
我该怎么做?请帮我。提前致谢。
【问题讨论】:
-
您发布的代码中没有语法错误。该错误很可能是这些行上方语法错误的结果。
-
@Mat 谢谢。在这里,我编辑并发布了整个代码以供参考。请帮帮我。
-
这是您的完整文件吗?您发布的内容仍然没有语法错误。
-
没有错误,因此尝试清理您的项目并运行
-
发布文件的其余部分,特别是包和导入的东西。
标签: android error-handling android-tabhost