在Androd_Tab_view.java文件,我有以下代碼:標籤視圖拋出異常
選項卡=(TabHost)findViewById(R.id.TabHost1); tabs.setup();
TabHost.TabSpec first_tab = tabs.newTabSpec("tag1");
first_tab.setContent(new Intent(this,FirstTab.class));
first_tab.setIndicator("Book");
tabs.addTab(first_tab);
//SecondTab.class
TabHost.TabSpec second_tab = tabs.newTabSpec("tag2");
second_tab.setContent(new Intent(this,SecondTab.class));
second_tab.setIndicator("Authors");
tabs.addTab(second_tab);
在FirstTab.java文件我有以下代碼:
public class FirstTab extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/* First Tab Content */
TextView textView = new TextView(this);
textView.setText("First Tab");
setContentView(textView);
}
}
在SecondTab.java文件我有以下代碼:
public class SecondTab extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState); /* Second Tab Content */
TextView textView = new TextView(this);
textView.setText("Second Tab");
setContentView(textView);
}
}
但是當我嘗試運行此代碼我得到一個異常。什麼可以解決這個問題?
請張貼logcat的。它會快速解決問題 – Simon