你tabhost那一段贴出来吧- -,还有homeactivity也要贴部分内容,别人才好判断,错误告诉你的是转型错误,光看log看不出来

解决方案 »

  1.   

    fragment_main.xml
    <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
       android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >    <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#fff0f1f1"
            android:orientation="vertical" >        <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="0.0dip"
                android:layout_weight="1.0" />        <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.0"
                android:visibility="gone" />        <FrameLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:layout_marginTop="-10.0dip"
                android:background="@drawable/maintab_toolbar_bg"
                android:paddingLeft="7.0dip"
                android:paddingRight="7.0dip" >            <RadioGroup
                    android:id="@+id/main_radio"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_vertical"
                    android:orientation="horizontal" >                <RadioButton
                        android:id="@+id/radio_home"
                        style="@style/main_tab_bottom"
                        android:drawableTop="@drawable/home"
                        android:text="@string/home" />                <RadioButton
                        android:id="@+id/radio_product"
                        style="@style/main_tab_bottom"
                        android:drawableTop="@drawable/product"
                        android:text="@string/product" />                <RadioButton
                        android:id="@+id/radio_model"
                        style="@style/main_tab_bottom"
                        android:drawableTop="@drawable/modle"
                        android:text="@string/model" />                <RadioButton
                        android:id="@+id/radio_vender"
                        style="@style/main_tab_bottom"
                        android:drawableTop="@drawable/vender"
                        android:text="@string/vender" />
                </RadioGroup>        </FrameLayout>
        </LinearLayout></TabHost>
      

  2.   

    MainActivity.java
    package com.example.hyt;import android.content.Intent;
    import android.os.Bundle;
    import android.support.v4.app.FragmentActivity;
    import android.widget.CompoundButton;
    import android.widget.CompoundButton.OnCheckedChangeListener;
    import android.widget.RadioButton;
    import android.widget.TabHost;
    import android.widget.TabHost.TabSpec;public class MainActivity extends FragmentActivity implements
    OnCheckedChangeListener {
    // 定义TAB选项卡标示符
    private static final String HOME_TAB = "home_tab";
    private static final String PRODUCT_TAB = "product_tab";
    private static final String MODEL_TAB = "model_tab";
    private static final String VENDER_TAB = "vender_tab"; // 定义Intent对象
    private Intent mHomeIntent, mProductIntent, mModelIntent, mVenderIntent; // 定义TabHost对象
    private TabHost mTabHost; // 定义单选按钮对象
    private RadioButton homeRb, productRb, modelRb, venderRb; @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fragment_main); initView(); initData(); } /**
     * 初始化组件
     */
    private void initView() {
    // TODO Auto-generated method stub
    // 得到TabHost
    //mTabHost = getTabHost(); mTabHost.setup();
    // 得到Intent对象
    mHomeIntent = new Intent(this, HomeActivity.class);
    mProductIntent = new Intent(this, ProductActivity.class);
    mModelIntent = new Intent(this, ModelActivity.class);
    mVenderIntent = new Intent(this, VenderActivity.class); // 得到单选按钮对象
    homeRb = ((RadioButton) findViewById(R.id.radio_home));
    productRb = ((RadioButton) findViewById(R.id.radio_product));
    modelRb = ((RadioButton) findViewById(R.id.radio_model));
    venderRb = ((RadioButton) findViewById(R.id.radio_vender));
    }
    /**
     * 初始化数据
     */
    private void initData() {
    // TODO Auto-generated method stub // 给单选按钮设置监听
    homeRb.setOnCheckedChangeListener(this);
    productRb.setOnCheckedChangeListener(this);
    modelRb.setOnCheckedChangeListener(this);
    venderRb.setOnCheckedChangeListener(this); // 添加tab选项卡
    mTabHost.addTab(buildTabSpec(HOME_TAB, mHomeIntent));
    mTabHost.addTab(buildTabSpec(PRODUCT_TAB, mProductIntent));
    mTabHost.addTab(buildTabSpec(MODEL_TAB, mModelIntent));
    mTabHost.addTab(buildTabSpec(VENDER_TAB, mVenderIntent)); // 设置当前默认的tab选项卡页面
    homeRb.setChecked(true);
    mTabHost.setCurrentTabByTag(HOME_TAB); } private TabSpec buildTabSpec(String homeTab, Intent mHomeIntent2) {
    // TODO Auto-generated method stub
    TabHost.TabSpec tabSpec = mTabHost.newTabSpec(homeTab);
    tabSpec.setContent(mHomeIntent2).setIndicator("");

    return tabSpec;
    } /**
     * Tab按钮选中监听事件
     */
    @Override
    public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
    // TODO Auto-generated method stub
    if(arg1){
    switch (arg0.getId()) {
    case R.id.radio_home:
    mTabHost.setCurrentTabByTag(HOME_TAB);
    break;
    case R.id.radio_product:
    mTabHost.setCurrentTabByTag(PRODUCT_TAB);
    break;
    case R.id.radio_model:
    mTabHost.setCurrentTabByTag(MODEL_TAB);
    break;
    case R.id.radio_vender:
    mTabHost.setCurrentTabByTag(VENDER_TAB);
    break;
    default:
    break;
    }
    } }}
      

  3.   

    homeactivity.java我还没写呢 刚建个类,看下效果就报错了!
      

  4.   

    那就怪不得了。。你一定是没在AndroidMainFest.xml里面配置
      

  5.   

    如果配置了,查看下homeactivity是否继承activity
      

  6.   

    在AndroidMainFest.xml里面配置了,homeactivity也继承Activity了
      

  7.   

    好了,我知道怎么回事,开始的时候MainActivity继承的TabActivity后来是过期的,当时homeActivity没有继承Activity,报错!后来我就换成fragment了,继承Activity,然后继续报错,后来改回来MainActivity继承的TabActivity后,就好了,谢谢!