期望的接收器类型,但得到android.support.v7.widget.TintContextWrapper
作者:互联网
我已经尝试了很多寻找解决方案.正如Same Question发现但它没有答案我想要的.
我有以下XML文件:
<LinearLayout
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:orientation="vertical"
android:id="@+id/add_appointment_parent_layout"
tools:context="com.potionowl.app.activity.AppointmentAddActivity">
<include layout="@layout/layout_toolbar"/>
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:padding="@dimen/padding_small"
android:layout_margin="@dimen/padding_medium"
android:layout_height="match_parent">
<android.support.v7.widget.AppCompatSpinner
android:id="@+id/add_appointment_doctor_spinner"
android:layout_width="match_parent"
android:prompt="@string/string_select_doctor_patient"
android:spinnerMode="dialog"
android:layout_margin="@dimen/padding_medium"
android:layout_height="wrap_content"/>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_margin="@dimen/padding_medium"
android:layout_height="wrap_content"
android:baselineAligned="false">
<android.support.design.widget.TextInputLayout
android:id="@+id/add_appointment_date_title"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_margin="@dimen/padding_very_small"
android:layout_height="wrap_content">
<EditText
android:id="@+id/add_appointment_date_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/string_add_app_date_for_appointment"
android:focusable="false"
android:onClick="PickDate"
android:singleLine="true"
android:inputType="datetime"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/add_appointment_time_title"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_margin="@dimen/padding_very_small"
android:layout_height="wrap_content">
<EditText
android:id="@+id/add_appointment_time_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/string_add_app_time_for_appointment"
android:focusable="false"
android:onClick="PickTime"
android:singleLine="true"
android:inputType="datetime"/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/add_appointment_symptoms_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/padding_medium">
<android.support.design.widget.TextInputEditText
android:id="@+id/add_appointment_symptoms_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="5"
android:gravity="start"
android:hint="@string/string_add_app_symptoms"
android:lines="5"/>
</android.support.design.widget.TextInputLayout>
<android.support.v7.widget.AppCompatButton
android:layout_width="wrap_content"
android:layout_gravity="center"
style="@style/Base.Widget.AppCompat.Button.Colored"
android:layout_margin="@dimen/padding_medium"
android:onClick="addAppointmentButtonClick"
android:layout_height="wrap_content"
android:text="@string/apply_for_appointment"/>
</LinearLayout>
</LinearLayout>
我得到的错误如下:
05-10 23:27:16.942 13455-13455/com.potionowl.app E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.potionowl.app, PID: 13455
java.lang.IllegalArgumentException: Expected receiver of type com.potionowl.app.activity.AppointmentAddActivity, but got android.support.v7.widget.TintContextWrapper
at java.lang.reflect.Method.invoke(Native Method)
at android.view.View$DeclaredOnClickListener.onClick(View.java:4456)
at android.view.View.performClick(View.java:5207)
at android.view.View$PerformClick.run(View.java:21168)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
我不知道为什么会这样.有什么解决方案吗?谢谢.
解决方法:
这与AppCompat扩展布局的方式有关.尝试将一个程序化的onClick侦听器添加到按钮,而不是在XML中执行.
有一个关于它的讨论on Google Code.这是因为你正在使用AppCompat按钮.
标签:android,android-activity,appcompat,appcompatactivity 来源: https://codeday.me/bug/20190527/1166859.html