1

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

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.

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

WorkbenchTicketDetailsActivity.java

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>

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.

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!!!

3
  • Is that the full stack trace? Commented Dec 9, 2011 at 17:26
  • I updated with the full trace in LogCat Commented Dec 9, 2011 at 17:48
  • I updated the ticketdetails.xml file to hold the <TabView layout at the root of the file (Remove encapsulating LinearLayout) but this had no effect. Still getting the same issue. Commented Dec 9, 2011 at 19:23

1 Answer 1

2

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

host.addTab(spec);

Sign up to request clarification or add additional context in comments.

1 Comment

You fixed it! I don't know how I missed that line after combing through it so many times. Thank you Warpzit!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.