android - 类型的预期接收者,但得到了 android.support.v7.widget.TintContextWrapper

标签 android android-activity android-appcompat appcompatactivity

我已经尝试了很多方法来寻找解决方案。正如 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.support.v7.widget.TintContextWrapper,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37145989/

相关文章:

java - 登录尝试持续时间

android - 资源是颜色还是可绘制对象?

java - 将倒数计时器值传递给下一个 Activity

android - 从两个应用程序访问同一个 sqlite 数据库

android - 找不到Android Studio 4.0.1默认 Activity

java - Android 中的 1 个布局中是否可以有 2 个 Activity ?

android - 导航到下一个 Activity 时更改操作栏颜色及其文本对齐方式

android - AppCompat v7 r21 更改 ActionBar 标题的 Alpha

android - SwitchCompat 在 4.3 及以下版本上缺少可绘制的拇指

java - 由于 appcompat v7,R.java 没有生成?