2016-06-11 4 views
1

Ich versuche, Datenbindung in meinem android app zu implementieren, aber ich bin mit diesem Thema fest:android Datenbindung - nicht Klasse finden android.view.data

java.lang.ClassNotFoundException: Didn't find class "android.view.data"

Meine Layout-Datei sieht wie folgt aus :

<layout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     tools:context="com.myapp.views.fragments.LocationSearchFragment"> 

     <!-- data setup --> 
     <data> 
      <variable name="location" 
       type="com.myapp.models.Address" /> 
     </data> 
    </LinearLayout> 
</layout> 

ich meine build.gradle Datei mit folgenden Zeilen aktualisiert:

dataBinding { 
    enabled = true 
} 

Wie die Dokumentation vorgeschlagen: https://developer.android.com/topic/libraries/data-binding/index.html. Ich verwende die neueste Version von Android Studio.

Antwort

1

Sie müssen außerhalb Ihres LinearLayout Ihre data Definition setzen:

<layout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools"> 
    <!-- data setup --> 
    <data> 
     <variable name="location" 
      type="com.myapp.models.Address" /> 
    </data> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     tools:context="com.myapp.views.fragments.LocationSearchFragment"> 
    </LinearLayout> 
</layout> 
1

Die Datenbindung ist nie in der <LinearLayout>. Sie sollten es in die <layout> Zone wie folgt setzen:

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


    <!-- data setup --> 
    <data> 
     <variable name="location" 
      type="com.myapp.models.Address" /> 
    </data> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    tools:context="com.myapp.views.fragments.LocationSearchFragment"> 

</LinearLayout> 
</layout>