java.lang.RuntimeException:无法启动活动ComponentInfo重复

时间:2013-01-31 04:41:46

标签: android android-layout android-intent

我知道这个问题经常被问到,但这个问题很不一样。日志文件只是多次发布上述异常而没有提到原因。日志文件如下所示


01-31 09:53:10.305: E/AndroidRuntime(452): FATAL EXCEPTION: main
01-31 09:53:10.305: E/AndroidRuntime(452): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.iolcalci/com.example.iolcalci.Second}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.iolcalci/com.example.iolcalci.Second}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.iolcalci/com.example.iolcalci.Second}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.iolcalci/com.example.iolcalci.Second}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.iolcalci/com.example.iolcalci.Second}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.iolcalci/com.example.iolcalci.Second}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.iolcalci/com.example.iolcalci.Second}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.iolcalci/com.example.iolcalci.Second}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.iolcalci/com.example.iolcalci.Second}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.iolcalci/com.example.iolcalci.Second}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.iolcalci/com.example.iolcalci.Second}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.iolcalci/com.example.iolcalci.Second}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.iolcalci/com.example.iolcalci.Second}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.iolcalci/com.example.iolcalci.Second}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.iolcalci/com.example.iolcalci.Second}: android.view.InflateException: Binary XML file line #37: Error inflating class <unknown>
01-31 09:53:10.305: E/AndroidRuntime(452):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
01-31 09:53:10.305: E/AndroidRuntime(452):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
01-31 09:53:10.305: E/AndroidRuntime(452):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-31 09:53:10.305: E/AndroidRuntime(452):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
01-31 09:53:10.305: E/AndroidRuntime(452):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-31 09:53:10.305: E/AndroidRuntime(452):  at android.os.Looper.loop(Looper.java:123)
01-31 09:53:10.305: E/AndroidRuntime(452):  at android.app.ActivityThread.main(ActivityThread.java:3683)
01-31 09:53:10.305: E/AndroidRuntime(452):  at java.lang.reflect.Method.invokeNative(Native Method)
01-31 09:53:10.305: E/AndroidRuntime(452):  at java.lang.reflect.Method.invoke(Method.java:507)
01-31 09:53:10.305: E/AndroidRuntime(452):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-31 09:53:10.305: E/AndroidRuntime(452):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-31 09:53:10.305: E/AndroidRuntime(452):  at dalvik.system.NativeStart.main(Native Method)
01-31 09:53:10.305: E/AndroidRuntime(452): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.iolcalci/com.example.iolcalci.Second}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.iolcalci/com.example.iolcalci.Second}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.iolcalci/com.example.iolcalci.Second}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.iolcalci/com.example.iolcalci.Second}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.iolcalci/com.example.iolcalci.Second}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.iolcalci/com.example.iolcalci.Second}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.iolcalci/com.example.iolcalci.Second}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.iolcalci/com.example.iolcalci.Second}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.iolcalci/com.example.iolcalci.Second}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.iolcalci/com.example.iolcalci.Second}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.iolcalci/com.example.iolcalci.Second}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.iolcalci/com.example.i

java文件如下所示

package com.example.iolcalci;


import com.itab.graphics.TabBitmap;

@SuppressWarnings("deprecation")
public class Second extends ActivityGroup {
    private TabHost mTabHost;
    private static final String TAG_1 = "tab1";
    private static final String TAG_2 = "tab2";
    private static final String TAG_3 = "tab3";
    private static final String TAG_4 = "tab4";

    @SuppressWarnings("deprecation")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.second);
        setTabs();
    }
    private void setTabs() {
        mTabHost = (TabHost) findViewById(android.R.id.tabhost);
        mTabHost.setup(getLocalActivityManager());

        addTab("SRK/T", TAG_1, createTabDrawable(R.drawable.ic_tab_eye_unselected), new Intent(this, Second.class));
        addTab("SRK II", TAG_2, createTabDrawable(R.drawable.ic_tab_eye_unselected), new Intent(this, Srk2_x.class));
        addTab("BINKHORST", TAG_3, createTabDrawable(R.drawable.ic_tab_eye_unselected), new Intent(this, Binkhorst_x.class));
        addTab("HOLLADAY", TAG_4, createTabDrawable(R.drawable.ic_tab_eye_unselected), new Intent(this, Holladay_x.class));
    }
    private Drawable createTabDrawable(int resId) {
        Resources res = getResources();
        StateListDrawable states = new StateListDrawable();

        final Options options = new Options();
        options.inPreferredConfig = Config.ARGB_8888;

        Bitmap icon = BitmapFactory.decodeResource(res, resId, options);

        Bitmap unselected = TabBitmap.createUnselectedBitmap(res, icon);
        Bitmap selected = TabBitmap.createSelectedBitmap(res, icon);

        icon.recycle();

        states.addState(new int[] { android.R.attr.state_selected }, new BitmapDrawable(res, selected));
        states.addState(new int[] { android.R.attr.state_enabled }, new BitmapDrawable(res, unselected));

        return states;
    }
    private View createTabIndicator(String label, Drawable drawable) {
        View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, mTabHost.getTabWidget(), false);

        TextView txtTitle = (TextView) tabIndicator.findViewById(R.id.text_view_tab_title);
        txtTitle.setText(label);
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) txtTitle.getLayoutParams();
        txtTitle.setLayoutParams(params);

        ImageView imgIcon = (ImageView) tabIndicator.findViewById(R.id.image_view_tab_icon);
        imgIcon.setImageDrawable(drawable);

        return tabIndicator;
    }

    private void addTab(String label, String tag, Drawable drawable, Intent intent) {
        TabHost.TabSpec spec = mTabHost.newTabSpec(tag);
        spec.setIndicator(createTabIndicator(label, drawable));
        spec.setContent(intent);
        mTabHost.addTab(spec);
    }


}

XML

 <?xml version="1.0" encoding="utf-8"?>


<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    tools:ignore="HardcodedText" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1"
            android:background="@color/Black" >

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="@dimen/tab_height" >
            </TabWidget>

            <TextView
                android:id="@+id/text_view_srkt"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:textSize="10sp" />

            <TextView
                android:id="@+id/text_view_srk2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:textSize="10sp" />

            <TextView
                android:id="@+id/text_view_holl"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:textSize="10sp" />

            <TextView
                android:id="@+id/text_view_bink"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:textSize="10sp" />
        </FrameLayout>
    </LinearLayout>

</TabHost>

请帮助。我无法弄清楚问题

1 个答案:

答案 0 :(得分:0)

我认为问题是由于这一行icon.recycle();,因为recycle()方法释放了与位图关联的本机对象,并清除了对像素数据的引用。所以试着像这样使用

 states.addState(new int[] { android.R.attr.state_selected }, new BitmapDrawable(res, selected));
        states.addState(new int[] { android.R.attr.state_enabled }, new BitmapDrawable(res, unselected));
        icon.recycle();