Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.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中禁用选项卡栏项目?_Android_Android Widget_Android Tabhost_Android Tabactivity_Android Tabs - Fatal编程技术网

如何在android中禁用选项卡栏项目?

如何在android中禁用选项卡栏项目?,android,android-widget,android-tabhost,android-tabactivity,android-tabs,Android,Android Widget,Android Tabhost,Android Tabactivity,Android Tabs,我正在制作我的第一个android应用程序。我想在我的android应用程序中禁用tab-bat项。我搜索并找到了以下方法: tabHost = (TabHost)findViewById(R.id.tabhost); tabHost.getTabWidget().getChildTabViewAt(your_index).setEnabled(false); 但它不工作,我得到以下错误: 06-11 16:53:15.927: D/AndroidRuntime(8466): Shutt

我正在制作我的第一个android应用程序。我想在我的android应用程序中禁用tab-bat项。我搜索并找到了以下方法:

 tabHost = (TabHost)findViewById(R.id.tabhost);
 tabHost.getTabWidget().getChildTabViewAt(your_index).setEnabled(false);
但它不工作,我得到以下错误:

 06-11 16:53:15.927: D/AndroidRuntime(8466): Shutting down VM
 06-11 16:53:15.927: W/dalvikvm(8466): threadid=1: thread exiting with uncaught exception (group=0x40028a00)
 06-11 16:53:16.037: D/dalvikvm(8466): GC_FOR_MALLOC freed 5350 objects / 347632 bytes in 98ms
 06-11 16:53:16.047: E/AndroidRuntime(8466): FATAL EXCEPTION: main
 06-11 16:53:16.047: E/AndroidRuntime(8466): java.lang.IllegalStateException: Could not execute method of the activity
 06-11 16:53:16.047: E/AndroidRuntime(8466):    at android.view.View$1.onClick(View.java:2072)
 06-11 16:53:16.047: E/AndroidRuntime(8466):    at android.view.View.performClick(View.java:2408)
 06-11 16:53:16.047: E/AndroidRuntime(8466):    at android.view.View$PerformClick.run(View.java:8817)
 06-11 16:53:16.047: E/AndroidRuntime(8466):    at android.os.Handler.handleCallback(Handler.java:587)
 06-11 16:53:16.047: E/AndroidRuntime(8466):    at android.os.Handler.dispatchMessage(Handler.java:92)
 06-11 16:53:16.047: E/AndroidRuntime(8466):    at android.os.Looper.loop(Looper.java:143)
 06-11 16:53:16.047: E/AndroidRuntime(8466):    at android.app.ActivityThread.main(ActivityThread.java:4914)
 06-11 16:53:16.047: E/AndroidRuntime(8466):    at java.lang.reflect.Method.invokeNative(Native Method)
 06-11 16:53:16.047: E/AndroidRuntime(8466):    at java.lang.reflect.Method.invoke(Method.java:521)
 06-11 16:53:16.047: E/AndroidRuntime(8466):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
 06-11 16:53:16.047: E/AndroidRuntime(8466):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
 06-11 16:53:16.047: E/AndroidRuntime(8466):    at dalvik.system.NativeStart.main(Native Method)
 06-11 16:53:16.047: E/AndroidRuntime(8466): Caused by: java.lang.reflect.InvocationTargetException
 06-11 16:53:16.047: E/AndroidRuntime(8466):    at com.eplinovo.runnoandroid.ActivityViewActivity.startClick(ActivityViewActivity.java:40)
 06-11 16:53:16.047: E/AndroidRuntime(8466):    at java.lang.reflect.Method.invokeNative(Native Method)
 06-11 16:53:16.047: E/AndroidRuntime(8466):    at java.lang.reflect.Method.invoke(Method.java:521)
 06-11 16:53:16.047: E/AndroidRuntime(8466):    at android.view.View$1.onClick(View.java:2067)
 06-11 16:53:16.047: E/AndroidRuntime(8466):    ... 11 more
 06-11 16:53:16.047: E/AndroidRuntime(8466): Caused by: java.lang.NullPointerException
 06-11 16:53:16.047: E/AndroidRuntime(8466):    ... 15 more

为什么我会这样?提前谢谢。

好的。转到logcat中错误的顶部,即ActivityViewActivity.startClick。继续,点击这一行。它将把您带到startClick方法中的某一行,其中有一个空指针。告诉我们那条线上有什么。可能是上面的那条线。如果是,例如 tabHost可能为null。单独检查这个

  tabHost.getWidget() 
  tagHost.getWidget().getChildTabViewAt(your_index)  // I bet its this one thats null.
如果上述任何一项为空,则假设导致问题的行是空的,则会得到该异常。如果不是的话,它在另一行上是类似的


所以,分而治之。找到线。将其拆分以查找可能为空的内容。然后在该行运行之前设置一个断点,并一次执行一行。将鼠标悬停在上方,查看每一步的空值。这就是在android中解决任何空指针的方法。

我没有正确使用tabhost

 tabHost = (TabHost)findViewById(R.id.tabhost);
以下是从子活动获取tabhost的正确方法:

 tabHost = (TabHost)getParent().findViewById(android.R.id.tabhost);