Thanks for the quick response Dianne.  Please find below the stack
trace, the fragment class' code and the layout XML.  I've tried using
either the default tabhost ID (android.R.id.tabhost) or an @+ ID.
Both result in the NullPointerException.

I'm sure it's a schoolboy error somewhere but if you (or anyone else)
can help I'd much appreciate it.

Stephen



-= Stack Trace =-

05-02 17:18:43.193: ERROR/AndroidRuntime(2446): FATAL EXCEPTION: main
05-02 17:18:43.193: ERROR/AndroidRuntime(2446):
java.lang.NullPointerException
05-02 17:18:43.193: ERROR/AndroidRuntime(2446):     at
android.widget.TabHost$ViewIdContentStrategy.<init>(TabHost.java:615)
05-02 17:18:43.193: ERROR/AndroidRuntime(2446):     at
android.widget.TabHost$ViewIdContentStrategy.<init>(TabHost.java:610)
05-02 17:18:43.193: ERROR/AndroidRuntime(2446):     at
android.widget.TabHost$TabSpec.setContent(TabHost.java:464)
05-02 17:18:43.193: ERROR/AndroidRuntime(2446):     at
uk.co.esstec.android.fragmenttabtest.ContentPaneFragment.onCreateView(ContentPaneFragment.java:
20)
05-02 17:18:43.193: ERROR/AndroidRuntime(2446):     at
android.app.FragmentManagerImpl.moveToState(FragmentManager.java:730)
05-02 17:18:43.193: ERROR/AndroidRuntime(2446):     at
android.app.FragmentManagerImpl.moveToState(FragmentManager.java:921)
05-02 17:18:43.193: ERROR/AndroidRuntime(2446):     at
android.app.BackStackRecord.run(BackStackRecord.java:578)
05-02 17:18:43.193: ERROR/AndroidRuntime(2446):     at
android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:
1221)
05-02 17:18:43.193: ERROR/AndroidRuntime(2446):     at
android.app.FragmentManagerImpl$1.run(FragmentManager.java:375)
05-02 17:18:43.193: ERROR/AndroidRuntime(2446):     at
android.os.Handler.handleCallback(Handler.java:587)
05-02 17:18:43.193: ERROR/AndroidRuntime(2446):     at
android.os.Handler.dispatchMessage(Handler.java:92)
05-02 17:18:43.193: ERROR/AndroidRuntime(2446):     at
android.os.Looper.loop(Looper.java:126)
05-02 17:18:43.193: ERROR/AndroidRuntime(2446):     at
android.app.ActivityThread.main(ActivityThread.java:3997)
05-02 17:18:43.193: ERROR/AndroidRuntime(2446):     at
java.lang.reflect.Method.invokeNative(Native Method)
05-02 17:18:43.193: ERROR/AndroidRuntime(2446):     at
java.lang.reflect.Method.invoke(Method.java:491)
05-02 17:18:43.193: ERROR/AndroidRuntime(2446):     at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:841)
05-02 17:18:43.193: ERROR/AndroidRuntime(2446):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
05-02 17:18:43.193: ERROR/AndroidRuntime(2446):     at
dalvik.system.NativeStart.main(Native Method)

-= Layout XML =-

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android";
        android:id="@+id/testtabhost1" android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <LinearLayout 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">
                        <TextView android:id="@+id/textview1"
android:layout_width="fill_parent"
                                android:layout_height="fill_parent" 
android:text="this is a tab" /
>
                        <TextView android:id="@+id/textview2"
android:layout_width="fill_parent"
                                android:layout_height="fill_parent" 
android:text="this is another
tab" />
                        <TextView android:id="@+id/textview3"
android:layout_width="fill_parent"
                                android:layout_height="fill_parent" 
android:text="this is a third
tab" />
                </FrameLayout>
        </LinearLayout>
</TabHost>

-= Fragment Class Code =-

package com.test.fragtest;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TabHost;

public class ContentPaneFragment extends Fragment {

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup
container,
                        Bundle savedInstanceState) {
                super.onCreateView(inflater, container, savedInstanceState);

                View v = inflater.inflate(R.layout.content_pane, container, 
false);

                TabHost mTabHost = (TabHost) v.findViewById(R.id.testtabhost1);

                
mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB
1").setContent(R.id.textview1));
                
mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("TAB
2").setContent(R.id.textview2));
                
mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("TAB
3").setContent(R.id.textview3));

                mTabHost.setCurrentTab(0);

                return v;
        }
}


On May 2, 2:36 pm, Dianne Hackborn <[email protected]> wrote:
> You can certainly use a TabHost inside of a fragment.  TabHost is just a
> view; it doesn't know anything about whatever is outside the view hierarchy
> it is running in.
>
> You haven't give the stack crawl of the exception, so it is hard to help
> further.
>
>
>
>
>
>
>
>
>
> On Mon, May 2, 2011 at 7:30 AM, Stephen <[email protected]> wrote:
> > Having read the post here:http://goo.gl/6xYBD(Android 3.0-Tabhost)
> > and based on the lack of a TabFragment it appears that the way to do
> > things in 3.0 (and I guess above) is to use tabs in the action bar.
>
> > My issue is that I'm writing an app that has the fairly standard
> > 'listview on left, content on right' layout, and I'd like my content
> > on the right to have tabs.  I know I can change the right fragment
> > using the tabs in the action bar, but from a UI perspective, it just
> > looks wrong.  The tabs in the action bar look like they preside over
> > the *whole* application as they are above the left ListView as well.
> > For example, in the HoneycombGallery app, the Android/Balloons/
> > Bikes.... tabs change both the ListView fragment and the content
> > fragment.  Mine would only change which aspect of the content you're
> > looking at.
>
> > I tried inflating a TabHost into the fragment but I get
> > NullPointerExceptions when I run TabSpec.setContent (that may be me
> > doing something wrong - I'll have another run at debugging it but
> > figured I'd ask this anyway).
>
> > I hope that all makes sense.  If I need to explain better please let
> > me know.  I'm very interested in how others are solving this problem
> > since I think the 'listview | content' style is quite common.  At the
> > moment, my alternatives are either to fake tabs with buttons
> > (something I'd rather avoid) or to present menu buttons in the action
> > bar to change what you're looking at.
>
> > Thank you,
>
> > Stephen
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to [email protected]
> > To unsubscribe from this group, send email to
> > [email protected]
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en
>
> --
> Dianne Hackborn
> Android framework engineer
> [email protected]
>
> Note: please don't send private questions to me, as I don't have time to
> provide private support, and so won't reply to such e-mails.  All such
> questions should be posted on public forums, where I and others can see and
> answer them.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to