0

I'm trying to create a TabHost in ListView in a TabHost, and I get the cast error.

enter code here  Process: com.example.vaidenv2, PID: 30623
java.lang.ClassCastException: com.example.vaidenv2.FQAGeneralFragment cannot be cast to android.support.v4.app.Fragment
        at android.support.v4.app.Fragment.instantiate(Fragment.java:420)
        at android.support.v4.app.FragmentTabHost.doTabChanged(FragmentTabHost.java:343)
        at android.support.v4.app.FragmentTabHost.onAttachedToWindow(FragmentTabHost.java:280)
        at android.view.View.dispatchAttachedToWindow(View.java:13406)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2707)
        at android.view.ViewGroup.addViewInner(ViewGroup.java:3919)
        at android.view.ViewGroup.addView(ViewGroup.java:3733)
        at android.view.ViewGroup.addView(ViewGroup.java:3678)
        at android.view.ViewGroup.addView(ViewGroup.java:3654)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:968)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1136)
        at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
        at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1499)
        at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:456)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5221)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

Here is my code in Fragment,

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTabHost;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;



public class FAQFragment extends Fragment{
FragmentTabHost mTabHost = null;

public View onCreateView(LayoutInflater inflater, ViewGroup    container,
                         Bundle savedInstanceState) {
    mTabHost = new FragmentTabHost(getActivity());

    mTabHost.setup(getActivity(), getChildFragmentManager(),
            android.R.id.tabcontent);

    mTabHost.addTab(mTabHost.newTabSpec("sub1").setIndicator("General"),
            FQAGeneralFragment.class, null);

    mTabHost.addTab(mTabHost.newTabSpec("sub2").setIndicator("Endor"),
            FQAEndorFragment.class, null);


    return mTabHost;
    }
}

Could someone help me to see how to solve this. And the library and package are all most recent version.

0

1 Answer 1

1

The Logcat error is pointing to FQAGeneralFragment as the error. I do not know FQAGeneralFragment type. I suspect it is not android.support.v4.app.Fragment class type. I would think FQAGeneralFragment is defined in another Java file, and you need to import android.support.v4.app.Fragment.

Please check it out and have fun...

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

1 Comment

@Maggie, You may select my answer to be the best correct answer by clicking on the checkmark icon. Thanks. Since you're new to Stackoverflow (SO), pls read up on its tutorial @ stackoverflow.com/tour . You will gain reputation points and a badge for it. Welcome to SO community and enjoy!

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.