First on error

Error code
04-15 21:50:15.332: D / AndroidRuntime (1042): Shutting down VM
04-15 21:50:15.332: W / dalvikvm (1042): threadid = 1: thread exiting with uncaught exception (group = 0x41465700)
04-15 21:50:15.342: E / AndroidRuntime (1042): FATAL EXCEPTION: main
04-15 21:50:15.342: E / AndroidRuntime (1042): java.lang.RuntimeException: Unable to start activity ComponentInfo {com.example.tabhost / com.example.tabhost.MainActivity}: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'
04-15 21:50:15.342: E / AndroidRuntime (1042): at android.app.ActivityThread.performLaunchActivity (ActivityThread.java: 2211)
04-15 21:50:15.342: E / AndroidRuntime (1042): at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java: 2261)
04-15 21:50:15.342: E / AndroidRuntime (1042): at android.app.ActivityThread.access $ 600 (ActivityThread.java: 141)
04-15 21:50:15.342: E / AndroidRuntime (1042): at android.app.ActivityThread $ H.handleMessage (ActivityThread.java: 1256)
04-15 21:50:15.342: E / AndroidRuntime (1042): at android.os.Handler.dispatchMessage (Handler.java: 99)
04-15 21:50:15.342: E / AndroidRuntime (1042): at android.os.Looper.loop (Looper.java: 137)
04-15 21:50:15.342: E / AndroidRuntime (1042): at android.app.ActivityThread.main (ActivityThread.java: 5103)
04-15 21:50:15.342: E / AndroidRuntime (1042): at java.lang.reflect.Method.invokeNative (Native Method)
04-15 21:50:15.342: E / AndroidRuntime (1042): at java.lang.reflect.Method.invoke (Method.java: 525)
04-15 21:50:15.342: E / AndroidRuntime (1042): at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java: 737)
04-15 21:50:15.342: E / AndroidRuntime (1042): at com.android.internal.os.ZygoteInit.main (ZygoteInit.java: 553)
04-15 21:50:15.342: E / AndroidRuntime (1042): at dalvik.system.NativeStart.main (Native Method)
04-15 21:50:15.342: E / AndroidRuntime (1042): Caused by: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'
04-15 21:50:15.342: E / AndroidRuntime (1042): at android.app.TabActivity.onContentChanged (TabActivity.java: 131)
04-15 21:50:15.342: E / AndroidRuntime (1042): at com.android.internal.policy.impl.PhoneWindow.setContentView (PhoneWindow.java: 270)
04-15 21:50:15.342: E / AndroidRuntime (1042): at android.app.Activity.setContentView (Activity.java: 1895)
04-15 21:50:15.342: E / AndroidRuntime (1042): at com.example.tabhost.MainActivity.onCreate (MainActivity.java: 22)
04-15 21:50:15.342: E / AndroidRuntime (1042): at android.app.Activity.performCreate (Activity.java: 5133)
04-15 21:50:15.342: E / AndroidRuntime (1042): at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java: 1087)
04-15 21:50:15.342: E / AndroidRuntime (1042): at android.app.ActivityThread.performLaunchActivity (ActivityThread.java: 2175)
04-15 21:50:15.342: E / AndroidRuntime (1042): ... 11 more
Layout:
xmlns: tools = "http://schemas.android.com/tools"
android: layout_width = "match_parent"
android: layout_height = "match_parent"
android: paddingBottom = "@ dimen / activity_vertical_margin"
android: paddingLeft = "@ dimen / activity_horizontal_margin"
android: paddingRight = "@ dimen / activity_horizontal_margin"
android: paddingTop = "@ dimen / activity_vertical_margin"
tools: context = "com.example.tabhost.MainActivity $ PlaceholderFragment">android: id = "@ android: id / tabhost"
android: layout_width = "match_parent"
android: layout_height = "match_parent">android: layout_width = "match_parent"
android: layout_height = "match_parent"
android: orientation = "vertical">android: id = "@ android: id / tabs"
android: layout_width = "match_parent"
android: layout_height = "wrap_content">
android: id = "@ android: id / tabcontent"
android: layout_width = "match_parent"
android: layout_height = "match_parent">android: id = "@ + id/tab1"
android: layout_width = "match_parent"
android: layout_height = "match_parent"
android: orientation = "vertical">android: id = "@ + id/txt1"
android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
android: text = "one" />
android: id = "@ + id/tab2"
android: layout_width = "match_parent"
android: layout_height = "match_parent"
android: orientation = "vertical">android: id = "@ + id/txt2"
android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
android: text = "two" />
android: id = "@ + id/tab3"
android: layout_width = "match_parent"
android: layout_height = "match_parent"
android: orientation = "vertical">
MainActivity code
package com.example.tabhost;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import android.app.TabActivity;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class MainActivity extends TabActivity {
@ Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
TabHost host = getTabHost ();
host.setup ();
TabSpec tab1 = host.newTabSpec ("tab1");
tab1.setIndicator (getResources () getString (R.string.tab1).);
tab1.setContent (R.id.tab1);
host.addTab (tab1);
TabSpec tab2 = host.newTabSpec ("tab2");
tab2.setIndicator (getResources () getString (R.string.tab2).);
tab2.setContent (R.id.tab2);
host.addTab (tab2);
TabSpec tab3 = host.newTabSpec ("tab3");
tab3.setIndicator (getResources () getString (R.string.tab3).);
tab3.setContent (R.id.tab3);
host.addTab (tab3);
host.setCurrentTab (0);
}
@ Override
public boolean onCreateOptionsMenu (Menu menu) {
/ / Inflate the menu; this adds items to the action bar if it is present
.getMenuInflater () inflate (R.menu.main, menu);.
return true;
}
@ Override
public boolean onOptionsItemSelected (MenuItem item) {
/ / Handle action bar item clicks here. The action bar will
/ / Automatically handle clicks on the Home / Up button, so long
/ / As you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId ();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected (item);
}
/ **
* A placeholder fragment containing a simple view.
* /
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment () {
}
@ Override
public View onCreateView (LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate (R.layout.fragment_main, container, false);
return rootView;
}
}
}
String code
tabhost Hello world! Settings picture 1 Screen 2 screen 3
These, knees and begged God to help more big ah! ! ! !
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
tools: context = "com.example.tabhost.MainActivity $ PlaceholderFragment" Here are removed to change the dollar sign and back under test.
Reply:
The amount of ... your tabhost is defined in fragment.xml inside of it, you put setContentView (R.layout.activity_main); inside the file into your layout that define tabhost
No comments:
Post a Comment