本文介绍了不能转换为TabActivity FragmentTabHost的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有延伸TabActivity类

由于TabActivity是德precated,我想用FragmentTabHost将其转换。
问题是,当我启动应用程序,我得到这个错误。
因为我还针对Android新手,有人可以帮助我如何解决这个问题。
TabActivity能给我一些问题,新设备或者我还可以用它白化问题?

感谢您

这是日志猫

  05-15 22:22:10.365:E / AndroidRuntime(2452):致命异常:主要
05-15 22:22:10.365:E / AndroidRuntime(2452):java.lang.ClassCastException:com.wilbur.app.ui.CatalogLocalListActivity不能转换为android.support.v4.app.Fragment
05-15 22:22:10.365:E / AndroidRuntime(2452):在android.support.v4.app.Fragment.instantiate(Fragment.java:402)
05-15 22:22:10.365:E / AndroidRuntime(2452):在android.support.v4.app.FragmentTabHost.doTabChanged(FragmentTabHost.java:343)
05-15 22:22:10.365:E / AndroidRuntime(2452):在android.support.v4.app.FragmentTabHost.onAttachedToWindow(FragmentTabHost.java:280)
05-15 22:22:10.365:E / AndroidRuntime(2452):在android.view.View.dispatchAttachedToWindow(View.java:12761)
05-15 22:22:10.365:E / AndroidRuntime(2452):在android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2642)
05-15 22:22:10.365:E / AndroidRuntime(2452):在android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2649)
05-15 22:22:10.365:E / AndroidRuntime(2452):在android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2649)
05-15 22:22:10.365:E / AndroidRuntime(2452):在android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2649)
05-15 22:22:10.365:E / AndroidRuntime(2452):在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1470)
05-15 22:22:10.365:E / AndroidRuntime(2452):在android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1230)
05-15 22:22:10.365:E / AndroidRuntime(2452):在android.view.ViewRootImpl $ TraversalRunnable.run(ViewRootImpl.java:5089)
05-15 22:22:10.365:E / AndroidRuntime(2452):在android.view.Choreographer $ CallbackRecord.run(Choreographer.java:791)
05-15 22:22:10.365:E / AndroidRuntime(2452):在android.view.Choreographer.doCallbacks(Choreographer.java:591)
05-15 22:22:10.365:E / AndroidRuntime(2452):在android.view.Choreographer.doFrame(Choreographer.java:561)
05-15 22:22:10.365:E / AndroidRuntime(2452):在android.view.Choreographer $ FrameDisplayEventReceiver.run(Choreographer.java:777)
05-15 22:22:10.365:E / AndroidRuntime(2452):在android.os.Handler.handleCallback(Handler.java:725)
05-15 22:22:10.365:E / AndroidRuntime(2452):在android.os.Handler.dispatchMessage(Handler.java:92)
05-15 22:22:10.365:E / AndroidRuntime(2452):在android.os.Looper.loop(Looper.java:137)
05-15 22:22:10.365:E / AndroidRuntime(2452):在android.app.ActivityThread.main(ActivityThread.java:5283)
05-15 22:22:10.365:E / AndroidRuntime(2452):在java.lang.reflect.Method.invokeNative(本机方法)
05-15 22:22:10.365:E / AndroidRuntime(2452):在java.lang.reflect.Method.invoke(Method.java:511)
05-15 22:22:10.365:E / AndroidRuntime(2452):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1102)
05-15 22:22:10.365:E / AndroidRuntime(2452):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
05-15 22:22:10.365:E / AndroidRuntime(2452):在dalvik.system.NativeStart.main(本机方法)

这是FragmentTabHost转化活动

 公共类CatalogTabHostActivity扩展FragmentActivity {公共静态最终诠释RESULT_EULA_CANCELED = 100;私有静态最后弦乐TAB_LOCAL =本地;保护无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.catalog_tab_host);
    mInstance =这一点;
    意向I = getIntent();
    捆绑额外= NULL;
    如果(我!= NULL){
        演员= i.getExtras();
    }
    FragmentTabHost mTab​​Host =(FragmentTabHost)findViewById(android.R.id.tabhost);
    mTabHost.setup(CatalogTabHostActivity.this,getSupportFragmentManager(),android.R.id.tabcontent);
    意图int​​entLocalCatalog =新意图(这一点,CatalogLocalListActivity.class);
    如果(临时演员!= NULL){
        intentLocalCatalog.putExtras(临时演员);
    }    mTabHost.addTab(mTabHost.newTabSpec(TAB_LOCAL).setIndicator(),CatalogLocalListActivity.class,NULL);
    mTabHost.getTabWidget()getChildTabViewAt(0).setVisibility(View.GONE)。
}保护无效onResume(){
    如果(!GlobalSettings.isAcceptedEULA(本)){
    }否则如果(!GlobalSettings.isChangeLogShowed(本)){
    // ChangeLogDialog.show(本);
        。ApplicationEx.getInstance()invalidateAutoUpdate();
        GlobalSettings.setChangeLogShowed(本);
    }
    super.onResume();
}私有静态CatalogTabHostActivity mInstance;公共静态活动的getInstance()
{
    返回mInstance;
}}

这是CatalogLocalListActivity

 公共类CatalogLocalListActivity扩展BaseCatalogActivity {公共静态最后弦乐EXTRA_INVOKE_LOCAL_UPDATE_LIST =EXTRA_INVOKE_LOCAL_UPDATE_LIST;私人布尔mInvokeSelectCurrent;
私人布尔mInvokeUpdateList;保护无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    mInvokeSelectCurrent =真;
    意图数据= getIntent();
    如果(数据!= NULL){
        mInvokeUpdateList = data.getBooleanExtra(EXTRA_INVOKE_LOCAL_UPDATE_LIST,FALSE);
    }
}保护无效setListView(){
    super.setListView();
    如果(mInvokeSelectCurrent){
        mInvokeSelectCurrent = FALSE;
        GlobalSettings.MapPath路径= GlobalSettings.getCurrentMap(本);
        串systemMapName = path.getSystemMapName();
        如果(systemMapName!= NULL){
            INT位置= mAdapter.findItemPosition(systemMapName);
            如果(位置!= - 1){
                mList.setSelection(位置);
            }
        }
    }
    如果(mInvokeUpdateList){
        mInvokeUpdateList = FALSE;
        invokeSelectUpdateMaps();
    }
}保护布尔isCatalogProgressEnabled(INT采用catalogId){
    返回采用catalogId == CatalogStorage.LOCAL;
}保护INT getEmptyListHeader(){
    返回R.string.msg_no_maps_in_local_header;
}保护INT getEmptyListMessage(){
    返回R.string.msg_no_maps_in_local;
}公众诠释getCatalogState(CatalogMap本地,远程CatalogMap){
    返回mRemote = NULL&放大器;!&安培; mLocal!= NULL? mStorageState.getLocalCatalogState(本地,远程):CatalogMapState.CALCULATING;
}公共布尔onCatalogMapClick(CatalogMap本地,远程CatalogMap,诠释状态){
    开关(州){
    案例计算:
        如果(local.isAvailable()){
            invokeFinish(局部);
        }其他{
            invokeMapDetails(本地,远程状态);
        }
        返回true;
    离线的情况下:
    情况下安装:
    案例更新:
        invokeFinish(局部);
        返回true;
    案例导入:
    案例下载:
    案例DOWNLOAD_PENDING:
    情况下装:
    案例IMPORT_PENDING:
    案例IMPORTING:
    案例NEED_TO_UPDATE:
    案例NOT_SUPPORTED:
    案例UPDATE_NOT_SUPPORTED:
    案例损坏:
        invokeMapDetails(本地,远程状态);
        返回true;
        // 没做什么
    }
    返回true;
}保护INT getDiffMode(){
    返回CatalogMapPair.DIFF_MODE_LOCAL;
}保护INT getLocalCatalogId(){
    返回CatalogStorage.LOCAL;
}保护INT getRemoteCatalogId(){
返回CatalogStorage.ONLINE;
}保护INT getDiffColors(){
    返回R.array.local_catalog_map_state_colors;
}/****************** 主菜单 ********************/私人最终诠释MAIN_MENU_UPDATE_MAPS = 1;
私人最终诠释MAIN_MENU_DELETE_MAPS = 2;私人最终静态INT REQUEST_UPDATE = 1;
私人最终静态INT REQUEST_DELETE = 2;公共布尔onCreateOptionsMenu(菜单菜单){
    super.onCreateOptionsMenu(菜单);
    menu.add(0,MAIN_MENU_UPDATE_MAPS,5,R.string.menu_update_maps).setIcon(R.drawable.icon_tab_import_selected);
    menu.add(0,MAIN_MENU_DELETE_MAPS,6,R.string.menu_delete_maps).setIcon(android.R.drawable.ic_menu_delete);
    返回true;
}prepareOptionsMenu(菜单菜单)上公共布尔{
    menu.findItem(MAIN_MENU_UPDATE_MAPS).setEnabled(mMode服务== MODE_LIST&放大器;&放大器;!mStorage.hasTasks());
    menu.findItem(MAIN_MENU_DELETE_MAPS).setEnabled(mMode服务== MODE_LIST&放大器;&放大器;!mStorage.hasTasks());
    返回super.on prepareOptionsMenu(菜单);
}公共布尔onOptionsItemSelected(菜单项项){
    开关(item.getItemId()){
    案例MAIN_MENU_UPDATE_MAPS:
        invokeSelectUpdateMaps();
        返回true;
    案例MAIN_MENU_DELETE_MAPS:
        invokeSelectDeleteMaps();
        返回true;
    }
    返回super.onOptionsItemSelected(项目);
}保护无效的onActivityResult(INT申请code,INT结果code,意图数据){
    开关(要求code){
    案例REQUEST_UPDATE:
        如果(结果code == RESULT_OK&放大器;&放大器;数据!= NULL){
            的String [] =名称data.getStringArrayExtra(CatalogMapSelectionActivity.EXTRA_SELECTION);
            对于(字符串的系统名称:名称){
                mStorage.requestDownload(系统名称);
            }
        }
        如果(结果code == CatalogMapSelectionActivity.RESULT_MAP_LIST_EMPTY){
            Toast.makeText(这一点,R.string.msg_no_maps_to_update,Toast.LENGTH_SHORT).show();
        }
        打破;
    案例REQUEST_DELETE:
        如果(结果code == RESULT_OK&放大器;&放大器;数据!= NULL){
            的String [] =名称data.getStringArrayExtra(CatalogMapSelectionActivity.EXTRA_SELECTION);
            对于(字符串的系统名称:名称){
                mStorage.deleteLocalMap(系统名称);
            }
        }
        如果(结果code == CatalogMapSelectionActivity.RESULT_MAP_LIST_EMPTY){
            Toast.makeText(这一点,R.string.msg_no_maps_to_delete,Toast.LENGTH_SHORT).show();
        }
        打破;
    }
    super.onActivityResult(要求code,结果code,数据);
}私人无效invokeSelectDeleteMaps(){
    意图I =新意图(这一点,CatalogMapSelectionActivity.class);
    i.putExtra(CatalogMapSelectionActivity.EXTRA_TITLE,它是gettext(R.string.menu_delete_maps));
    i.putExtra(CatalogMapSelectionActivity.EXTRA_REMOTE_ID,CatalogStorage.ONLINE);
    i.putExtra(CatalogMapSelectionActivity.EXTRA_REMOTE_MODE,CatalogMapPair.DIFF_MODE_LOCAL);
    i.putExtra(CatalogMapSelectionActivity.EXTRA_FILTER,mActionBarEditText.getText()的toString());
    i.putExtra(CatalogMapSelectionActivity.EXTRA_SORT_MODE,CheckedCatalogAdapter.SORT_MODE_COUNTRY);
    startActivityForResult(ⅰ,REQUEST_DELETE);
}私人无效invokeSelectUpdateMaps(){
    意图I =新意图(这一点,CatalogMapSelectionActivity.class);
    i.putExtra(CatalogMapSelectionActivity.EXTRA_TITLE,它是gettext(R.string.menu_update_maps));
    i.putExtra(CatalogMapSelectionActivity.EXTRA_REMOTE_ID,CatalogStorage.ONLINE);
    i.putExtra(CatalogMapSelectionActivity.EXTRA_FILTER,mActionBarEditText.getText()的toString());
    i.putExtra(CatalogMapSelectionActivity.EXTRA_SORT_MODE,CheckedCatalogAdapter.SORT_MODE_COUNTRY);
    i.putExtra(CatalogMapSelectionActivity.EXTRA_CHECKABLE_STATES,新的INT [] {CatalogMapState.UPDATE,CatalogMapState.NEED_TO_UPDATE});
    i.putExtra(CatalogMapSelectionActivity.EXTRA_VISIBLE_STATES,新的INT [] {CatalogMapState.UPDATE,CatalogMapState.NEED_TO_UPDATE});
    startActivityForResult(ⅰ,REQUEST_UPDATE);
}
 }


解决方案

引用的的文档 FragmentTabHost

You are attempting to put an Activity as its tab content. Please convert that to be a Fragment.

这篇关于不能转换为TabActivity FragmentTabHost的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-07 20:09