After migration to androidX: Databinding problem (Android Studio 4)

独自空忆成欢 提交于 2021-01-29 10:32:19

问题


I migrated a project to androidx. I changed the xml-files by hand an I also set the imports manually, where Android Studio wasn't successful. When I try to rebuild the project, the following error occurs in the compiled file DataBinderMapperImpl.java

The head of this file:

package com.xxxx.todo;

import android.util.SparseArray;
import android.util.SparseIntArray;
import android.view.View;
import androidx.databinding.DataBinderMapper;
import androidx.databinding.DataBindingComponent;
import androidx.databinding.ViewDataBinding;
import com.xxxx.todo.databinding.***ActivityDetailviewBindingImpl***; <--red
import java.lang.IllegalArgumentException;
import java.lang.Integer;
import java.lang.Object;
import java.lang.Override;
import java.lang.RuntimeException;
import java.lang.String;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class DataBinderMapperImpl extends DataBinderMapper {
  private static final int LAYOUT_ACTIVITYDETAILVIEW = 1;

  private static final SparseIntArray INTERNAL_LAYOUT_ID_LOOKUP = new SparseIntArray(1);

  static {
    INTERNAL_LAYOUT_ID_LOOKUP.put(com.xxxx.todo.R.layout.activity_detailview, LAYOUT_ACTIVITYDETAILVIEW);
  }

  @Override
  public ViewDataBinding getDataBinder(DataBindingComponent component, View view, int layoutId) {
    int localizedLayoutId = INTERNAL_LAYOUT_ID_LOOKUP.get(layoutId);
    if(localizedLayoutId > 0) {
      final Object tag = view.getTag();
      if(tag == null) {
        throw new RuntimeException("view must have a tag");
      }
      switch(localizedLayoutId) {
        case  LAYOUT_ACTIVITYDETAILVIEW: {
          if ("layout/activity_detailview_0".equals(tag)) {
            return new ***ActivityDetailviewBindingImpl***(component, view);
          }
          throw new IllegalArgumentException("The tag for activity_detailview is invalid. Received: " + tag);
        }
      }
    }
    return null;
  }

C:\Users\xxxx\Desktop\ToDo_v2\ToDo_v2\app\build\generated\ap_generated_sources\debug\out\com\xxxx\todo\DataBinderMapperImpl.java:9: error: cannot find symbol
import com.xxxx.todo.databinding.ActivityDetailviewBindingImpl;
  symbol:   class ActivityDetailviewBindingImpl
  location: package com.xxxx.todo.databinding

This is the corresponding xml-file:

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

<layout xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <data>
        <variable
            name="todo"
            type="com.xxxx.model.Todo"/>
        <variable
            name="actions"
            type="com.xxxx.view.DetailviewActions"/>
    </data>

    <androidx.constraintlayout.widget.ConstraintLayout

        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorDanger"
        android:padding="10dp">

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/todoNameContainer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/todoNameLabel">

            <com.google.android.material.textfield.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="text"
                android:maxLines="1"
                android:text="@={todo.name}" />
        </com.google.android.material.textfield.TextInputLayout>

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/todoDescriptionContainer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/todoDescriptionLabel"
            app:layout_constraintTop_toBottomOf="@id/todoNameContainer">

            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/todoDescription"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@={todo.description}" />
        </com.google.android.material.textfield.TextInputLayout>


        <LinearLayout
            android:id="@+id/todoDateContainer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:orientation="vertical"
            app:layout_constraintTop_toBottomOf="@id/todoDescriptionContainer">

            <TextView
                android:id="@+id/todoDateDescription"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Datum"
                android:textSize="13dp" />

            <TextView
                android:id="@+id/todoDateText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:onClick="@{() -> actions.setDate()}"
                android:text="@{todo.getDateString()}"
                android:textSize="20dp" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:onClick="@{() -> actions.pickContact()}"
                android:text="Kontakte"
                android:textSize="13dp" />
        </LinearLayout>

        <ScrollView
            android:id="@+id/scrollView"
            style="@android:style/Widget.DeviceDefault.ScrollView"
            android:layout_width="match_parent"
            android:layout_height="150dp"
            android:background="@color/colorDanger"
            android:scrollbarStyle="insideOverlay"
            app:layout_constraintTop_toBottomOf="@id/todoDateContainer"
            tools:layout_editor_absoluteX="10dp">

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

            </LinearLayout>

        </ScrollView>

        <LinearLayout
            android:id="@+id/doneContainer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:orientation="horizontal"
            app:layout_constraintTop_toBottomOf="@id/scrollView">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:minWidth="300dp"
                android:text="Erledigt"
                android:textSize="20dp" />

            <CheckBox
                android:id="@+id/todoDoneCheckbox"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="@={todo.done}"
                android:focusable="false"
                android:gravity="center"
                android:onCheckedChanged="@{() -> actions.toggleDone()}" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintTop_toBottomOf="@id/doneContainer">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:minWidth="300dp"
                android:text="Favorit?"
                android:textSize="20dp" />

            <Switch
                android:id="@+id/todoFavouriteSwitch"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="@={todo.favourite}"
                android:focusable="false"
                android:gravity="center"
                android:onCheckedChanged="@{() -> actions. toggleFavourite()}" />
        </LinearLayout>


        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/saveTodoButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="@{() -> actions.saveTodo()}"
            android:src="@drawable/baseline_save_white_24"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintRight_toRightOf="parent" />

        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/deleteButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:onClick="@{() -> actions.deleteTodo()}"
            android:src="@drawable/ic_delete_forever_white_24dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent" />

    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>

回答1:


Solution: I had accidentally changed

<android.support.design.widget.TextInputEditText

into

<com.google.android.material.textfield.TextInputLayout

while going through the xml-files by hand during migration to androidx. Should have been:

<com.google.android.material.textfield.TextInputEditText

Now it works.



来源:https://stackoverflow.com/questions/62433911/after-migration-to-androidx-databinding-problem-android-studio-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!