D Myers
D Myers

Reputation: 91

Android Studio - generated binding class cannot find symbol if in package

I have set up a package under my main namespace (com.company.product.Model) to contain my models and am using databinding. When the databinding class is generated, I am getting an error stating that it cannot find the symbol (which is the package i set up for my models). If I move the model into the com.company.product package... all compiles and runs. Move back into com.company.product.Model and same error. All the searching I have done pointed to naming of the XML file, enabling databinding in gradle.... all of which have been done. Have also done the whole clean, rebuild, restart thing to no avail. I am sure it is something stupid that I am missing, but could use a second set of eyes.

Package structure:

Generated binding class:

package com.company.product.databinding;

import android.databinding.Bindable;
import android.databinding.DataBindingComponent;
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;
import com.company.product.Model;

public abstract class TimesheetEntryBinding extends ViewDataBinding {
  @NonNull
  public final EditText hoursText1;

  @NonNull
  public final EditText hoursText2;

  @NonNull
  public final EditText hoursText3;

  @NonNull
  public final EditText hoursText4;

  @NonNull
  public final EditText hoursText5;

  @NonNull
  public final EditText hoursText6;

  @NonNull
  public final EditText hoursText7;

  @NonNull
  public final TextView projectNameText;

  @Bindable
  protected Model.TimesheetEntry mEntry;

  protected TimesheetEntryBinding(DataBindingComponent _bindingComponent, View _root,
      int _localFieldCount, EditText hoursText1, EditText hoursText2, EditText hoursText3,
      EditText hoursText4, EditText hoursText5, EditText hoursText6, EditText hoursText7,
      TextView projectNameText) {
    super(_bindingComponent, _root, _localFieldCount);
    this.hoursText1 = hoursText1;
    this.hoursText2 = hoursText2;
    this.hoursText3 = hoursText3;
    this.hoursText4 = hoursText4;
    this.hoursText5 = hoursText5;
    this.hoursText6 = hoursText6;
    this.hoursText7 = hoursText7;
    this.projectNameText = projectNameText;
  }

  public abstract void setEntry(@Nullable Model.TimesheetEntry entry);

  @Nullable
  public Model.TimesheetEntry getEntry() {
    return mEntry;
  }

  @NonNull
  public static TimesheetEntryBinding inflate(@NonNull LayoutInflater inflater,
      @Nullable ViewGroup root, boolean attachToRoot) {
    return inflate(inflater, root, attachToRoot, DataBindingUtil.getDefaultComponent());
  }

  @NonNull
  public static TimesheetEntryBinding inflate(@NonNull LayoutInflater inflater,
      @Nullable ViewGroup root, boolean attachToRoot, @Nullable DataBindingComponent component) {
    return DataBindingUtil.<TimesheetEntryBinding>inflate(inflater, com.company.product.R.layout.timeentry_item, root, attachToRoot, component);
  }

  @NonNull
  public static TimesheetEntryBinding inflate(@NonNull LayoutInflater inflater) {
    return inflate(inflater, DataBindingUtil.getDefaultComponent());
  }

  @NonNull
  public static TimesheetEntryBinding inflate(@NonNull LayoutInflater inflater,
      @Nullable DataBindingComponent component) {
    return DataBindingUtil.<TimesheetEntryBinding>inflate(inflater, com.company.product.R.layout.timeentry_item, null, false, component);
  }

  public static TimesheetEntryBinding bind(@NonNull View view) {
    return bind(view, DataBindingUtil.getDefaultComponent());
  }

  public static TimesheetEntryBinding bind(@NonNull View view,
      @Nullable DataBindingComponent component) {
    return (TimesheetEntryBinding)bind(component, view, com.company.product.R.layout.timeentry_item);
  }
}

This is the xml

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <data class="TimesheetEntryBinding">
        <import type="android.view.View"/>
        <variable
            name="entry"
            type="com.company.product.Model.TimesheetEntry" />
    </data>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/projectNameText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@{entry.projectName}" />

        <HorizontalScrollView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">
                <EditText
                    android:id="@+id/hoursText1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:width="@dimen/time_timeEntryWidth"
                    android:ems="10"
                    android:inputType="numberDecimal"
                    android:text="" />
                <EditText
                    android:id="@+id/hoursText2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:width="@dimen/time_timeEntryWidth"
                    android:ems="10"
                    android:inputType="numberDecimal"
                    android:text="" />
                <EditText
                    android:id="@+id/hoursText3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:width="@dimen/time_timeEntryWidth"
                    android:ems="10"
                    android:inputType="numberDecimal"
                    android:text="" />
                <EditText
                    android:id="@+id/hoursText4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:width="@dimen/time_timeEntryWidth"
                    android:ems="10"
                    android:inputType="numberDecimal"
                    android:text="" />
                <EditText
                    android:id="@+id/hoursText5"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:width="@dimen/time_timeEntryWidth"
                    android:ems="10"
                    android:inputType="numberDecimal"
                    android:text="" />
                <EditText
                    android:id="@+id/hoursText6"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:width="@dimen/time_timeEntryWidth"
                    android:ems="10"
                    android:inputType="numberDecimal"
                    android:text="" />
                <EditText
                    android:id="@+id/hoursText7"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:width="@dimen/time_timeEntryWidth"
                    android:ems="10"
                    android:inputType="numberDecimal"
                    android:text="" />
            </LinearLayout>
        </HorizontalScrollView>
    </LinearLayout>
</layout>

Upvotes: 0

Views: 1097

Answers (1)

D Myers
D Myers

Reputation: 91

I found out what I was doing wrong from this post: Data binding "error: cannot find symbol class Models" .

I had named my package "Model" instead of "model". Once I refactored... the databinding classes built.

Upvotes: 1

Related Questions