Android App - returning Null Pointer Exception on Eclair
<p>I am having an issue with an Android app I am writing.  It crashes on Eclair due to a <code>NullPointerException</code> but runs fine on Froyo and Gingerbread.  Can anyone tell me how to rewrite this to avoid the Null Pointer Exception?  Thanks in advance.</p>

<p><strong>Edit</strong>
I added the stack trace and logcat, I might have read it wrong originally, looks like it could be my <code>TabWidget</code>?</p>

<p>logcat references this line in my <code>Home</code> class:</p>

<pre><code>tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("Snow", res.getDrawable(R.drawable.weather2)).setContent(new Intent(this,FirstTab.class))); 
</code></pre>

<p><strong>Logcat</strong></p>

<pre><code>ERROR/AndroidRuntime(314): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.wilcoxis.android.kirkwood/com.wilcoxis.android.Home}: java.lang.NullPointerException
ERROR/AndroidRuntime(314):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
ERROR/AndroidRuntime(314):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
ERROR/AndroidRuntime(314):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)
ERROR/AndroidRuntime(314):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
ERROR/AndroidRuntime(314):     at android.os.Handler.dispatchMessage(Handler.java:99)
ERROR/AndroidRuntime(314):     at android.os.Looper.loop(Looper.java:123)
ERROR/AndroidRuntime(314):     at android.app.ActivityThread.main(ActivityThread.java:4363)
ERROR/AndroidRuntime(314):     at java.lang.reflect.Method.invokeNative(Native Method)
ERROR/AndroidRuntime(314):     at java.lang.reflect.Method.invoke(Method.java:521)
ERROR/AndroidRuntime(314):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
ERROR/AndroidRuntime(314):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
ERROR/AndroidRuntime(314):     at dalvik.system.NativeStart.main(Native Method)
ERROR/AndroidRuntime(314): Caused by: java.lang.NullPointerException
ERROR/AndroidRuntime(314):     at android.widget.TabWidget.onFocusChange(TabWidget.java:351)
ERROR/AndroidRuntime(314):     at android.view.View.onFocusChanged(View.java:2622)
ERROR/AndroidRuntime(314):     at android.view.View.handleFocusGainInternal(View.java:2445)
ERROR/AndroidRuntime(314):     at android.view.ViewGroup.handleFocusGainInternal(ViewGroup.java:404)
ERROR/AndroidRuntime(314):     at android.view.View.requestFocus(View.java:3562)
ERROR/AndroidRuntime(314):     at android.view.ViewGroup.requestFocus(ViewGroup.java:976)
ERROR/AndroidRuntime(314):     at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:1021)
ERROR/AndroidRuntime(314):     at android.view.ViewGroup.requestFocus(ViewGroup.java:977)
ERROR/AndroidRuntime(314):     at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:1021)
ERROR/AndroidRuntime(314):     at android.view.ViewGroup.requestFocus(ViewGroup.java:980)
ERROR/AndroidRuntime(314):     at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:1021)
ERROR/AndroidRuntime(314):     at android.view.ViewGroup.requestFocus(ViewGroup.java:977)
ERROR/AndroidRuntime(314):     at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:1021)
ERROR/AndroidRuntime(314):     at android.view.ViewGroup.requestFocus(ViewGroup.java:980)
ERROR/AndroidRuntime(314):     at android.view.View.requestFocus(View.java:3513)
ERROR/AndroidRuntime(314):     at android.view.View.requestFocus(View.java:3491)
ERROR/AndroidRuntime(314):     at android.widget.TabHost.setCurrentTab(TabHost.java:334)
ERROR/AndroidRuntime(314):     at android.widget.TabHost.addTab(TabHost.java:213)
ERROR/AndroidRuntime(314):     at com.wilcoxis.android.Home.onCreate(Home.java:83)
ERROR/AndroidRuntime(314):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
ERROR/AndroidRuntime(314):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
ERROR/AndroidRuntime(314):     ... 11 more
</code></pre>

<p><strong>Stack Trace</strong></p>

<pre><code>DalvikVM[localhost:8610]    
    Thread [&lt;3&gt; main] (Suspended (exception NullPointerException))  
        TabWidget.onFocusChange(View, boolean) line: 351    
        TabWidget(View).onFocusChanged(boolean, int, Rect) line: 2622   
        TabWidget(View).handleFocusGainInternal(int, Rect) line: 2445   
        TabWidget(ViewGroup).handleFocusGainInternal(int, Rect) line: 404   
        TabWidget(View).requestFocus(int, Rect) line: 3562  
        TabWidget(ViewGroup).requestFocus(int, Rect) line: 976  
        LinearLayout(ViewGroup).onRequestFocusInDescendants(int, Rect) line: 1021   
        LinearLayout(ViewGroup).requestFocus(int, Rect) line: 977   
        TabHost(ViewGroup).onRequestFocusInDescendants(int, Rect) line: 1021    
        TabHost(ViewGroup).requestFocus(int, Rect) line: 980    
        FrameLayout(ViewGroup).onRequestFocusInDescendants(int, Rect) line: 1021    
        FrameLayout(ViewGroup).requestFocus(int, Rect) line: 977    
        PhoneWindow$DecorView(ViewGroup).onRequestFocusInDescendants(int, Rect) line: 1021  
        PhoneWindow$DecorView(ViewGroup).requestFocus(int, Rect) line: 980  
        PhoneWindow$DecorView(View).requestFocus(int) line: 3513    
        PhoneWindow$DecorView(View).requestFocus() line: 3491   
        TabHost.setCurrentTab(int) line: 334    
        TabHost.addTab(TabHost$TabSpec) line: 213   
        Home.onCreate(Bundle) line: 83  
        Instrumentation.callActivityOnCreate(Activity, Bundle) line: 1047   
        ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2459  
        ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2512   
        ActivityThread.access$2200(ActivityThread, ActivityThread$ActivityRecord, Intent) line: 119 
        ActivityThread$H.handleMessage(Message) line: 1863  
        ActivityThread$H(Handler).dispatchMessage(Message) line: 99 
        Looper.loop() line: 123 
        ActivityThread.main(String[]) line: 4363    
        Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
        Method.invoke(Object, Object...) line: 521  
        ZygoteInit$MethodAndArgsCaller.run() line: 860  
        ZygoteInit.main(String[]) line: 618 
        NativeStart.main(String[]) line: not available [native method]  
    Thread [&lt;13&gt; Binder Thread #2] (Running)    
    Thread [&lt;11&gt; Binder Thread #1] (Running)
</code></pre>
