我正在为TabActivity开发一个简单的例子......当我试图运行时......它显示以下异常.... log cat view ....
04-29 16:13:04.870: ERROR/Zygote(33): setreuid() failed. errno: 2
04-29 16:13:17.520: ERROR/Zygote(33): setreuid() failed. errno: 17
04-29 16:13:20.940: ERROR/BatteryService(60): usbOnlinePath not found
04-29 16:13:20.940: ERROR/BatteryService(60): batteryVoltagePath not found
04-29 16:13:20.940: ERROR/BatteryService(60): batteryTemperaturePath not found
04-29 16:13:20.980: ERROR/SurfaceFlinger(60): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake
04-29 16:13:33.001: ERROR/EventHub(60): could not get driver version for /dev/input/mouse0, Not a typewriter
04-29 16:13:33.001: ERROR/EventHub(60): could not get driver version for /dev/input/mice, Not a typewriter
04-29 16:13:33.401: ERROR/System(60): Failure starting core service
04-29 16:13:33.401: ERROR/System(60): java.lang.SecurityException
04-29 16:13:33.401: ERROR/System(60): at android.os.BinderProxy.transact(Native Method)
04-29 16:13:33.401: ERROR/System(60): at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146)
04-29 16:13:33.401: ERROR/System(60): at android.os.ServiceManager.addService(ServiceManager.java:72)
04-29 16:13:33.401: ERROR/System(60): at com.android.server.ServerThread.run(SystemServer.java:184)
04-29 16:13:35.430: ERROR/SoundPool(60): error loading /system/media/audio/ui/Effect_Tick.ogg
04-29 16:13:35.450: ERROR/SoundPool(60): error loading /system/media/audio/ui/KeypressStandard.ogg
04-29 16:13:35.470: ERROR/SoundPool(60): error loading /system/media/audio/ui/KeypressSpacebar.ogg
04-29 16:13:35.480: ERROR/SoundPool(60): error loading /system/media/audio/ui/KeypressDelete.ogg
04-29 16:13:35.500: ERROR/SoundPool(60): error loading /system/media/audio/ui/KeypressReturn.ogg
04-29 16:13:39.790: ERROR/ThrottleService(60): Could not open GPS configuration file /etc/gps.conf
04-29 16:13:42.600: ERROR/logwrapper(153): executing /system/bin/tc failed: No such file or directory
04-29 16:13:42.691: ERROR/logwrapper(154): executing /system/bin/tc failed: No such file or directory
04-29 16:13:42.800: ERROR/logwrapper(155): executing /system/bin/tc failed: No such file or directory
04-29 16:14:06.081: ERROR/HierarchicalStateMachine(60): TetherMaster - unhandledMessage: msg.what=3
04-29 16:14:50.237: ERROR/AndroidRuntime(301): FATAL EXCEPTION: main
04-29 16:14:50.237: ERROR/AndroidRuntime(301): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android/com.android.tab_sample}: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'
04-29 16:14:50.237: ERROR/AndroidRuntime(301): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-29 16:14:50.237: ERROR/AndroidRuntime(301): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-29 16:14:50.237: ERROR/AndroidRuntime(301): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-29 16:14:50.237: ERROR/AndroidRuntime(301): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-29 16:14:50.237: ERROR/AndroidRuntime(301): at android.os.Handler.dispatchMessage(Handler.java:99)
04-29 16:14:50.237: ERROR/AndroidRuntime(301): at android.os.Looper.loop(Looper.java:123)
04-29 16:14:50.237: ERROR/AndroidRuntime(301): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-29 16:14:50.237: ERROR/AndroidRuntime(301): at java.lang.reflect.Method.invokeNative(Native Method)
04-29 16:14:50.237: ERROR/AndroidRuntime(301): at java.lang.reflect.Method.invoke(Method.java:521)
04-29 16:14:50.237: ERROR/AndroidRuntime(301): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-29 16:14:50.237: ERROR/AndroidRuntime(301): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-29 16:14:50.237: ERROR/AndroidRuntime(301): at dalvik.system.NativeStart.main(Native Method)
04-29 16:14:50.237: ERROR/AndroidRuntime(301): Caused by: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'
04-29 16:14:50.237: ERROR/AndroidRuntime(301): at android.app.TabActivity.onContentChanged(TabActivity.java:105)
04-29 16:14:50.237: ERROR/AndroidRuntime(301): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:201)
04-29 16:14:50.237: ERROR/AndroidRuntime(301): at android.app.Activity.setContentView(Activity.java:1647)
04-29 16:14:50.237: ERROR/AndroidRuntime(301): at com.android.tab_sample.onCreate(tab_sample.java:14)
04-29 16:14:50.237: ERROR/AndroidRuntime(301): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-29 16:14:50.237: ERROR/AndroidRuntime(301): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-29 16:14:50.237: ERROR/AndroidRuntime(301): ... 11 more
04-29 16:29:46.777: ERROR/AndroidRuntime(738): FATAL EXCEPTION: main
04-29 16:29:46.777: ERROR/AndroidRuntime(738): **java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android/com.android.tab_sample}: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'**
04-29 16:29:46.777: ERROR/AndroidRuntime(738): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-29 16:29:46.777: ERROR/AndroidRuntime(738): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-29 16:29:46.777: ERROR/AndroidRuntime(738): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-29 16:29:46.777: ERROR/AndroidRuntime(738): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-29 16:29:46.777: ERROR/AndroidRuntime(738): at android.os.Handler.dispatchMessage(Handler.java:99)
04-29 16:29:46.777: ERROR/AndroidRuntime(738): at android.os.Looper.loop(Looper.java:123)
04-29 16:29:46.777: ERROR/AndroidRuntime(738): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-29 16:29:46.777: ERROR/AndroidRuntime(738): at java.lang.reflect.Method.invokeNative(Native Method)
04-29 16:29:46.777: ERROR/AndroidRuntime(738): at java.lang.reflect.Method.invoke(Method.java:521)
04-29 16:29:46.777: ERROR/AndroidRuntime(738): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-29 16:29:46.777: ERROR/AndroidRuntime(738): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-29 16:29:46.777: ERROR/AndroidRuntime(738): at dalvik.system.NativeStart.main(Native Method)
04-29 16:29:46.777: ERROR/AndroidRuntime(738): Caused by: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'
04-29 16:29:46.777: ERROR/AndroidRuntime(738): at android.app.TabActivity.onContentChanged(TabActivity.java:105)
04-29 16:29:46.777: ERROR/AndroidRuntime(738): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:201)
04-29 16:29:46.777: ERROR/AndroidRuntime(738): at android.app.Activity.setContentView(Activity.java:1647)
04-29 16:29:46.777: ERROR/AndroidRuntime(738): at com.android.tab_sample.onCreate(tab_sample.java:14)
04-29 16:29:46.777: ERROR/AndroidRuntime(738): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-29 16:29:46.777: ERROR/AndroidRuntime(738): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-29 16:29:46.777: ERROR/AndroidRuntime(738): ... 11 more
我的代码是......
package com.android;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;
public class tab_sample extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.tab_sample);
TabHost tab=(TabHost)findViewById(R.id.tabhost);
tab.setup();
Resources res=getResources();
//tab=getTabHost();
Intent int1=new Intent(this,tab1.class);
Intent int2=new Intent(this,tab2.class);
tab.addTab(tab.newTabSpec("tab1").setIndicator("Songs",res.getDrawable(R.drawable.tab1)).setContent(int1));
tab.addTab(tab.newTabSpec("tab2").setIndicator("Movie",res.getDrawable(R.drawable.tab2)).setContent(int2));
//tab.addTab(tab.newTabSpec("tab3"))
tab.setCurrentTab(0);
}
}
请帮我解决这个问题....
答案 0 :(得分:1)
在xml中,你的tabhost id应为id =“@ android:id / tabhost”检查:Android Tab Host
答案 1 :(得分:0)
一些重要的logcat行是:
16:29:46.777:ERROR / AndroidRuntime(738):引起:java.lang.RuntimeException:你的内容必须有一个TabHost,其id属性为'android.R.id.tabhost'04-29 16:29 :46.777:
好像它找不到你的id,但这很奇怪,因为那会产生编译错误。您是否以某种方式动态更改/创建ID?
答案 2 :(得分:0)
如果您正在使用库中的某些其他活动,请确保布局文件不同。例如。避免使用双main.xml文件。