Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用tabActivity运行应用程序时出错_Android_Android Tabhost - Fatal编程技术网

Android 使用tabActivity运行应用程序时出错

Android 使用tabActivity运行应用程序时出错,android,android-tabhost,Android,Android Tabhost,我正在为TabActivity开发一个简单的示例…当我尝试运行时…它显示了以下异常。。。。日志cat视图 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

我正在为TabActivity开发一个简单的示例…当我尝试运行时…它显示了以下异常。。。。日志cat视图

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);
    }

}

请帮助我解决此问题。…

一些重要的logcat行包括:

16:29:46.777:错误/AndroidRuntime(738):原因:java.lang.RuntimeException:您的内容必须具有id属性为“android.R.id.TabHost”的TabHost 04-29 16:29:46.777:


似乎找不到您的id,但这很奇怪,因为这会导致编译错误。您是否以某种方式动态更改/创建id?

在xml中,您的tabhost id应为id=“@android:id/tabhost”检查此项:

如果您正在使用库中的其他活动,请确保布局文件不同。例如,避免使用双重main.xml文件。

否。我仅在xml文件中创建了id。