在jellybean中输出类android.widget.CheckBox时出错

时间:2016-06-07 07:34:27

标签: android checkbox

我正在尝试创建一个复选框。它适用于棉花糖和棒棒糖。但是在软糖中我得到了上述错误。

选中复选框时显示对话框,单击取消时取消选中。 我不知道我做错了什么。请帮忙

这是布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/custom_activity_title"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"

tools:context="com.prematix.busticketdesign.BookTicketActivity">


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


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="6dp"
        android:background="@drawable/custom_activity_title"
        android:orientation="vertical"
        android:weightSum="1">  <!--Logo-->

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_margin="8dp"

            android:gravity="center"
            android:padding="5dp"
            android:text="Book Ticket"

            android:textColor="#ffffff"
            android:textSize="20dp" />
    </LinearLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:id="@+id/forScroll"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="1dp"
                android:background="@drawable/edittext_style"
                android:orientation="vertical"
                android:padding="5dp"
                android:weightSum="1">


                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="3dp"
                    android:fontFamily="sans-serif-medium"
                    android:text="Name"
                    android:textSize="15dp" />

                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="3dp"
                    android:fontFamily="sans-serif-light"
                    android:hint="Enter Name"
                    android:textSize="15dp" />


            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="1dp"
                android:background="@drawable/edittext_style"
                android:orientation="vertical"

                android:padding="5dp"
                android:weightSum="1">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="3dp"
                    android:fontFamily="sans-serif-medium"
                    android:text="Phone number"
                    android:textSize="15dp" />

                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="3dp"
                    android:fontFamily="sans-serif-light"
                    android:hint="Enter phone number"
                    android:inputType="number"
                    android:textSize="15dp" />


            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="1dp"
                android:background="@drawable/edittext_style"
                android:orientation="horizontal"

                android:weightSum="1">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="3dp"
                    android:layout_weight="0.5"
                    android:fontFamily="sans-serif-medium"
                    android:padding="5dp"
                    android:text="Service Name"
                    android:textSize="15dp" />

                <Spinner
                    android:id="@+id/serviceNameSpinner"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="0.5"
                    android:prompt="@string/hello_world"></Spinner>

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="1dp"
                android:background="@drawable/edittext_style"
                android:orientation="horizontal"

                android:padding="5dp"
                android:weightSum="1">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="3dp"
                    android:padding="5dp"
                    android:fontFamily="sans-serif-medium"
                    android:text="From"
                    android:layout_weight="0.5"
                    android:textSize="15dp" />

                <Spinner
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="3dp"
                    android:id="@+id/fromSpinner"
                    android:layout_weight="0.5"
                    android:textSize="15dp" />


            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="1dp"
                android:background="@drawable/edittext_style"
                android:orientation="horizontal"
                android:padding="5dp"
                android:weightSum="1">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="3dp"
                    android:fontFamily="sans-serif-medium"
                    android:layout_weight="0.5"
                    android:text="Destination"
                    android:textSize="15dp" />

                <Spinner
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="3dp"
                    android:id="@+id/destinationSpinner"
                    android:layout_weight="0.5"
                    android:textSize="15dp" />


            </LinearLayout>


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="1dp"
                android:background="@drawable/edittext_style"
                android:orientation="vertical"
                android:padding="5dp"
                android:weightSum="1">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="3dp"
                    android:fontFamily="sans-serif-medium"

                    android:text="Seat number"
                    android:textSize="15dp" />

                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="3dp"
                    android:fontFamily="sans-serif-light"
                    android:hint="Enter seat number"
                    android:inputType="number"
                    android:textSize="15dp" />


            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:padding="8dp"
                android:background="@drawable/edittext_style">

                <CheckBox
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Luggage"
                    android:id="@+id/luggageCheckBox"/>

            </LinearLayout>


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:orientation="horizontal"
                android:weightSum="1">



                <Button
                    android:id="@+id/bookButton"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@drawable/custom_button_menu1"
                    android:layout_margin="4dp"
                    android:text="Book"
                    android:textColor="#ffffff" />

            </LinearLayout>
        </LinearLayout>
    </ScrollView>

</LinearLayout>

这是错误日志:

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.prematix.busticketdesign/com.prematix.busticketdesign.BookTicketActivity}: android.view.InflateException: Binary XML file line #237: Error inflating class android.widget.CheckBox
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2351)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2403)
        at android.app.ActivityThread.access$600(ActivityThread.java:165)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:194)
        at android.app.ActivityThread.main(ActivityThread.java:5391)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:525)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
        at dalvik.system.NativeStart.main(Native Method)
 Caused by: android.view.InflateException: Binary XML file line #237: Error inflating class android.widget.CheckBox
        at android.view.LayoutInflater.createView(LayoutInflater.java:613)
        at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:274)
        at android.app.Activity.setContentView(Activity.java:1881)
        at com.prematix.busticketdesign.BookTicketActivity.onCreate(BookTicketActivity.java:31)
        at android.app.Activity.performCreate(Activity.java:5122)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1150)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2315)

at

android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2403)
            at android.app.ActivityThread.access$600(ActivityThread.java:165)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
            at android.os.Handler.dispatchMessage(Handler.java:107)
            at android.os.Looper.loop(Looper.java:194)
            at android.app.ActivityThread.main(ActivityThread.java:5391)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.reflect.InvocationTargetException
            at java.lang.reflect.Constructor.constructNative(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
            at android.view.LayoutInflater.createView(LayoutInflater.java:587)
            at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
            at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:274)
            at android.app.Activity.setContentView(Activity.java:1881)
            at com.prematix.busticketdesign.BookTicketActivity.onCreate(BookTicketActivity.java:31)
            at android.app.Activity.performCreate(Activity.java:5122)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1150)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2315)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2403)
            at android.app.ActivityThread.access$600(ActivityThread.java:165)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
            at android.os.Handler.dispatchMessage(Handler.java:107)
            at android.os.Looper.loop(Looper.java:194)
            at android.app.ActivityThread.main(ActivityThread.java:5391)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_btn_check_material.xml from drawable resource ID #0x7f020003
            at android.content.res.Resources.loadDrawable(Resources.java:1993)
            at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
            at android.widget.CompoundButton.<init>(CompoundButton.java:74)
            at android.widget.CheckBox.<init>(CheckBox.java:68)
            at android.widget.CheckBox.<init>(CheckBox.java:64)
            at java.lang.reflect.Constructor.constructNative(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
            at android.view.LayoutInflater.createView(LayoutInflater.java:587)
            at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
            at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:274)
            at android.app.Activity.setContentView(Activity.java:1881)
            at com.prematix.busticketdesign.BookTicketActivity.onCreate(BookTicketActivity.java:31)
            at android.app.Activity.performCreate(Activity.java:5122)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1150)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2315)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2403)
            at android.app.ActivityThread.access$600(ActivityThread.java:165)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
            at android.os.Handler.dispatchMessage(Handler.java:107)
            at android.os.Looper.loop(Looper.java:194)
            at android.app.ActivityThread.main(ActivityThread.java:5391)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_btn_checkbox_checked_mtrl.xml from drawable resource ID #0x7f020004
            at android.content.res.Resources.loadDrawable(Resources.java:1993)
            at android.content.res.Resources.getDrawable(Resources.java:673)
            at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:173)
            at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:885)
            at android.graphics.drawable.Drawable.createFromXml(Drawable.java:822)
            at android.content.res.Resources.loadDrawable(Resources.java:1990)
            at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
            at android.widget.CompoundButton.<init>(CompoundButton.java:74)
            at android.widget.CheckBox.<init>(CheckBox.java:68)
            at android.widget.CheckBox.<init>(CheckBox.java:64)
            at java.lang.reflect.Constructor.constructNative(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
            at android.view.LayoutInflater.createView(LayoutInflater.java:587)
            at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
            at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:274)
            at android.app.Activity.setContentView(Activity.java:1881)
            at com.prematix.busticketdesign.BookTicketActivity.onCreate(BookTicketActivity.java:31)
            at android.app.Activity.performCreate(Activity.java:5122)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1150)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2315)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2403)
            at android.app.ActivityThread.access$600(ActivityThread.java:165)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
            at android.os.Handler.dispatchMessage(Handler.java:107)
            at android.os.Looper.loop(Looper.java:194)
            at android.app.ActivityThread.main(ActivityThread.java:5391)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #17: invalid drawable tag vector
            at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:881)
            at android.graphics.drawable.Drawable.createFromXml(Drawable.java:822)
            at android.conte

1 个答案:

答案 0 :(得分:1)

根错误消息是&#34;无效的可绘制标记向量&#34;。 JellyBean不支持VectorDrawables。

您可以使用vector-compat等支持库在JellyBean上使用VectorDrawable。