2.3.3 以降のバージョンで動作するアプリで ActionBarSherlock を使用しています。フラグメント タブ ホストのアプリケーションでListView
、アクティビティの 1 つに実装しようとしていますが、取得していClassCastException
ます。必要なコードが添付されています。
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;
}
にはCreateEvent.class
listView があります。
public class CreateEvent extends SherlockListActivity implements OnItemClickListener{
}
ログキャット
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)