Android的tabHost空指针 [英] Android tabHost NullPointer

查看:175
本文介绍了Android的tabHost空指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新到Android编程而不是Java的。

I'm new to android programming but not to Java.

我已经得到有关在一个NPE此错误消息:

I've been getting this error message regarding a NPE at:

12-09 10:29:58.247: D/dalvikvm(471): GC freed 711 objects / 54912 bytes in 163ms
12-09 10:29:58.337: D/dalvikvm(471): GC freed 45 objects / 1720 bytes in 37ms
12-09 10:29:58.457: D/AndroidRuntime(471): Shutting down VM
12-09 10:29:58.457: W/dalvikvm(471): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
12-09 10:29:58.457: E/AndroidRuntime(471): Uncaught handler: thread main exiting due to uncaught exception
12-09 10:29:58.457: E/AndroidRuntime(471): java.lang.NullPointerException
12-09 10:29:58.457: E/AndroidRuntime(471):  at android.widget.TabHost.dispatchWindowFocusChanged(TabHost.java:295)
12-09 10:29:58.457: E/AndroidRuntime(471):  at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661)
12-09 10:29:58.457: E/AndroidRuntime(471):  at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661)
12-09 10:29:58.457: E/AndroidRuntime(471):  at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661)
12-09 10:29:58.457: E/AndroidRuntime(471):  at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661)
12-09 10:29:58.457: E/AndroidRuntime(471):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1819)
12-09 10:29:58.457: E/AndroidRuntime(471):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-09 10:29:58.457: E/AndroidRuntime(471):  at android.os.Looper.loop(Looper.java:123)
12-09 10:29:58.457: E/AndroidRuntime(471):  at android.app.ActivityThread.main(ActivityThread.java:4363)
12-09 10:29:58.457: E/AndroidRuntime(471):  at java.lang.reflect.Method.invokeNative(Native Method)
12-09 10:29:58.457: E/AndroidRuntime(471):  at java.lang.reflect.Method.invoke(Method.java:521)
12-09 10:29:58.457: E/AndroidRuntime(471):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
12-09 10:29:58.457: E/AndroidRuntime(471):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
12-09 10:29:58.457: E/AndroidRuntime(471):  at dalvik.system.NativeStart.main(Native Method)
12-09 10:29:58.467: I/dalvikvm(471): threadid=7: reacting to signal 3
12-09 10:29:58.467: E/dalvikvm(471): Unable to open stack trace file '/data/anr/traces.txt': Permission denied

它的驾驶我疯了。我搜索了一个解决方案,在线,而我看到的错误引用多次,他们要么没有解决方案,张贴或解决方案不为我工作。

It's driving me mad. I've searched for a solution online and while I see the error referenced many times, they either don't have solutions posted or the solutions don't work for me.

下面是我的文件。我AP preciate任何帮助,您可以给我。

Here are my files. I appreciate any help you can give me.

package com.android.fm.workbench;
import com.android.fm.workbench.R;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class WorkbenchTicketDetailsActivity extends WorkbenchActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.ticketdetails);
    TabHost host = (TabHost)findViewById(R.id.tabhost);
    host.setup();
    TabSpec ticketdetailTab = host.newTabSpec("ticketdetails");
    ticketdetailTab.setIndicator(getResources().getString(R.string.tablabel_ticketdetails),getResources().getDrawable(android.R.drawable.ic_menu_manage));
    ticketdetailTab.setContent(R.id.TableLayout_TicketDetails);

    host.setCurrentTabByTag("ticketdetails");


    }
}

ticketdetails.xml

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/fm_background"
        android:orientation="vertical" >
       <TabHost 
       xmlns:android="http://schemas.android.com/apk/res/android"  
        android:id="@+id/tabhost"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent">
       <LinearLayout 
          android:id="@+id/LinearLayout1"
          android:orientation="vertical"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent">
          <TabWidget
              android:id="@android:id/tabs"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content" />
          <FrameLayout 
              android:id="@android:id/tabcontent"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">
              <ScrollView 
                  android:id="@+id/ScrollViewTicketDetails"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:scrollbars="vertical">
                  <TableLayout
                      android:id="@+id/TableLayout_TicketDetails"
                      android:layout_width="fill_parent"
                      android:layout_height="fill_parent"
                      android:stretchColumns="*">
                      <TableRow
                          android:layout_width="fill_parent"
                          android:layout_height="wrap_content"
                          >
                          <TextView 
                          android:layout_width="fill_parent"
                          android:layout_height="wrap_content"
        android:text="test"
                              />
                      </TableRow>
                  </TableLayout>
              </ScrollView>
          </FrameLayout>              
      </LinearLayout>
   </TabHost>
</LinearLayout>

的Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.fm.workbench"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="7" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".WorkbenchActivity" >
        </activity>
        <activity android:name="WorkbenchTicketDetailsActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/><category     android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>
        <activity android:name="WorkbenchLoginActivity"></activity>
        <activity android:name="WorkbenchSplashActivity">
        </activity>
    </application>

</manifest>

我appologize如果有,我只是没有看到一个简单的解决方案。我一直在敲我的头靠在了半晌一张桌子,我知道有很多的超级巨星在这里可以快速找到问题。

I appologize if this there is a simple solution that I'm just not seeing. I've been banging my head against a desk for a long while and I know there are a lot of superstars on here that can spot issues quickly.

我试着从TabView的Andr​​oid的网站加入下面的code和替换现有的ticketdetail.xml code:

I tried adding the following code from the Android site on TabView and replacing my existing ticketdetail.xml code with :

<?xml version="1.0" encoding="utf-8"?>
    <TabHost xmlns:android="http://schemas.android.com/apk/res/android"    
        android:id="@android:id/tabhost"    
        android:layout_width="fill_parent"    
        android:layout_height="fill_parent">    
        <LinearLayout        
            android:orientation="vertical"        
            android:layout_width="fill_parent"        
            android:layout_height="fill_parent"        
            android:padding="5dp">        
            <TabWidget            
                android:id="@android:id/tabs"            
                android:layout_width="fill_parent"            
                android:layout_height="wrap_content" />        
            <FrameLayout            
                android:id="@android:id/tabcontent"            
                android:layout_width="fill_parent"            
                android:layout_height="fill_parent"            
                android:padding="5dp" />    
        </LinearLayout>
</TabHost>

仍然给我一个空指针异常!

Still gives me a null pointer exception!!!

推荐答案

为什么要你主持你不添加则tabspec?

Why don't you add your tabspec to you host?

host.addTab(规范);

host.addTab(spec);

这篇关于Android的tabHost空指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆