0

I am using ActionBarSherlock in my app that works for 2.3.3 and higher version. In my application in fragment tab host I am trying to implement ListView in one of the activities but I am getting ClassCastException . Please find necessary code attached .

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {


            // Create FragmentTabHost
            mTabHost = new FragmentTabHost(getSherlockActivity());
            // Locate fragment1.xml to create FragmentTabHostx
            mTabHost.setup(getSherlockActivity(), getChildFragmentManager(), R.layout.fragment1);
          // Create Tab 1

            mTabHost.addTab(
                    mTabHost.newTabSpec("tab1").setIndicator("ALL",
                            getResources().getDrawable(R.drawable.all)),
                    CreateEvent.class, null);
            //mTabHost.addTab(mTabHost.newTabSpec("tab1").setContent(R.drawable.fb).setIndicator("Tab 1"), CreateEvent.class, null);
                 // Create Tab 2
            mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator("NEARBY",getResources().getDrawable(R.drawable.near_by)), CreateEvent.class, null);

            mTabHost.getTabWidget().setBackgroundColor(Color.GRAY);
            return mTabHost;
        }

The CreateEvent.class has a listView in it . public class CreateEvent extends SherlockListActivity implements OnItemClickListener{ }

Logcat

08-22 18:37:48.237: E/AndroidRuntime(917): FATAL EXCEPTION: main
08-22 18:37:48.237: E/AndroidRuntime(917): java.lang.ClassCastException: com.android.myapp.events.CreateEvent
08-22 18:37:48.237: E/AndroidRuntime(917):  at android.support.v4.app.Fragment.instantiate(Fragment.java:394)
08-22 18:37:48.237: E/AndroidRuntime(917):  at android.support.v4.app.FragmentTabHost.doTabChanged(FragmentTabHost.java:339)
08-22 18:37:48.237: E/AndroidRuntime(917):  at android.support.v4.app.FragmentTabHost.onAttachedToWindow(FragmentTabHost.java:276)
08-22 18:37:48.237: E/AndroidRuntime(917):  at android.view.View.dispatchAttachedToWindow(View.java:6156)
08-22 18:37:48.237: E/AndroidRuntime(917):  at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1122)
08-22 18:37:48.237: E/AndroidRuntime(917):  at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
08-22 18:37:48.237: E/AndroidRuntime(917):  at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
08-22 18:37:48.237: E/AndroidRuntime(917):  at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
08-22 18:37:48.237: E/AndroidRuntime(917):  at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
08-22 18:37:48.237: E/AndroidRuntime(917):  at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
08-22 18:37:48.237: E/AndroidRuntime(917):  at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
08-22 18:37:48.237: E/AndroidRuntime(917):  at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
08-22 18:37:48.237: E/AndroidRuntime(917):  at android.view.ViewRoot.performTraversals(ViewRoot.java:765)
08-22 18:37:48.237: E/AndroidRuntime(917):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
08-22 18:37:48.237: E/AndroidRuntime(917):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-22 18:37:48.237: E/AndroidRuntime(917):  at android.os.Looper.loop(Looper.java:123)
08-22 18:37:48.237: E/AndroidRuntime(917):  at android.app.ActivityThread.main(ActivityThread.java:3683)
08-22 18:37:48.237: E/AndroidRuntime(917):  at java.lang.reflect.Method.invokeNative(Native Method)
08-22 18:37:48.237: E/AndroidRuntime(917):  at java.lang.reflect.Method.invoke(Method.java:507)
08-22 18:37:48.237: E/AndroidRuntime(917):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-22 18:37:48.237: E/AndroidRuntime(917):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-22 18:37:48.237: E/AndroidRuntime(917):  at dalvik.system.NativeStart.main(Native Method)
3
  • so you wana cast some Activity to Fragment? ... good luck Commented Aug 22, 2013 at 13:20
  • In fragmenttabhost I wish to show a ListView Commented Aug 22, 2013 at 13:22
  • for FSM sake !!! CreateEvent extends Activity but it should extends ListFragment since you're using FragmentTabHost and you wana have ListView ... there should be some class in ABS API for this ... Commented Aug 22, 2013 at 13:25

1 Answer 1

1

I was trying to solve the problem with wrong approach.I used this question as guide to solve the problem.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.