2017-04-05 15 views
0

私はこの問題についてより多くのリンクを読んでいますが、私のプロジェクトの正確な問題は何か分かりません。私はアンドロイドパッケージ* .databindingは存在しません

apply plugin: 'com.android.application' 
apply plugin: 'com.neenbedankt.android-apt' 

android { 
    compileSdkVersion 25 
    buildToolsVersion "25.0.2" 
    defaultConfig { 
     applicationId "com.text.myapp" 
     minSdkVersion 15 
     targetSdkVersion 25 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
    dataBinding { 
     enabled = true 
    } 
} 

repositories { 
    jcenter() 
    maven { url "https://jitpack.io" } 
    maven { url "https://clojars.org/repo/" } 
} 

def support_library = "25.2.0" 

dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    compile "com.android.support:appcompat-v7:${support_library}" 
    compile "com.android.support:support-v13:${support_library}" 
    compile "com.android.support:cardview-v7:${support_library}" 
    compile "com.android.support:recyclerview-v7:${support_library}" 
} 
私のアプリケーション build.gradleファイルの内容である

コードの下に、 build.gradleの真私の活動を dataBindingを設定します。

public class ActivityRegister extends AppCompatActivity { 

    private ActivityRegisterBinding binding; 

    @Override 
    public void onCreate(@Nullable Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     binding = DataBindingUtil.setContentView(this, R.layout.activity_register); 
    } 
} 

とLogcatで、その後、活動のレイアウト

<?xml version="1.0" encoding="utf-8"?> 
<layout 
    xmlns:android="http://schemas.android.com/apk/res/android"> 

    <data> 
     <variable 
      name="presenter" 
      type="ir.pishguy.cafealachiqpro.Ui.Register.ActivityMain.Model.ActivityRegisterViewModel"/> 
    </data> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_margin="-5dp" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/default_port" 
      android:layout_width="match_parent" 
      android:visibility="gone" 
      android:layout_height="@dimen/default_textview_height"/> 
    </LinearLayout> 
</layout> 

エラー:

/Users/mahdi/Desktop/Home/Projects/Android/CafeAlachiqPro/app/src/main/java/com/text/myapp/Ui/Register/ActivityMain/Presenter/ActivityRegister.java 
Error:(11, 45) error: package com.text.myapp.databinding does not exist 
Error:(19, 13) error: cannot find symbol class ActivityRegisterBinding 
Warning:The following options were not recognized by any processor: 
'[android.databinding.artifactType, android.databinding.printEncodedErrors, android.databinding.minApi, android.databinding.isTestVariant, android.databinding.enableDebugLogs, android.databinding.sdkDir, android.databinding.bindingBuildFolder, android.databinding.enableForTests, android.databinding.modulePackage, android.databinding.generationalFileOutDir, android.databinding.xmlOutDir]' 
Error:Execution failed for task ':app:compileDebugJavaWithJavac'. 
> Compilation failed; see the compiler error output for details. 

私のViewModel:

public class ActivityRegisterViewModel extends BaseObservable { 
    private String readContactPermission; 
    private String getMessages; 

    public ActivityRegisterViewModel() { 
    } 

    @Bindable 
    public String getReadContactPermission() { 
     return readContactPermission; 
    } 

    public void setReadContactPermission(String readContactPermission) { 
     this.readContactPermission = readContactPermission; 
     notifyChange(); 
    } 

    public String getGetMessages() { 
     return getMessages; 
    } 

    public void setGetMessages(String getMessages) { 
     this.getMessages = getMessages; 
    } 
} 
+0

から解決することはできません、更新お使いのエラー –

+0

@SurajMakhijaポストを投稿してくださいありがとう –

答えて

0

次のようにあなたのviewmodelを定義する変数タグを明記してください:

<?xml version="1.0" encoding="utf-8"?> 
    <layout 
     xmlns:android="http://schemas.android.com/apk/res/android"> 

     <data> 

      <variable 
       name="<variablename>" 
       type="<packagename.YourViewModel>" /> 
     </data> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_margin="-5dp" 
      android:orientation="vertical"> 

      <TextView 
       android:id="@+id/default_port" 
       android:layout_width="match_parent" 
       android:visibility="gone" 
       android:layout_height="@dimen/default_textview_height"/> 
     </LinearLayout> 
    </layout> 
+0

この解決策は私の問題を解決することができませんでした –

+0

同じエラーが発生していますか? –

+0

viewmodelを作成しましたが、それをあなたのXMLで定義できましたか? –

1

は、プラグインを適用する

を削除: 'com.neenbedankt.android-aptの'

および

apt "com.github.Raizlabs.DBFlow:dbflow-processor:$ {dbflow_version}"

from gradle。これは私がこのエラーを取り除くのに役立ちます。

私はあなたのプロジェクトの原因ir.pishguy.cafealachiqpro.Ui.Register.Robot.Model.RobotViewModelを実行することもできますがはrobot_user_action.xml

<data class="UserMessagesDataBinding"> 

     <variable 
      name="viewModel" 
      type="ir.pishguy.cafealachiqpro.Ui.Register.Robot.Model.RobotViewModel"> 
     </variable> 
    </data> 
+0

oh、created newプロジェクト私はあなたがそれを見つけることができるこのパッケージを持っていない?私の平均は 'type =" ir.pishguy.cafealachiqpro.Ui.Register.Robot.Model.RobotViewModel "' –

+0

です。自分の投稿にレイアウトコンテンツを貼り付け、この行のレイアウトファイルをクリックします。 'binding = DataBindingUtil.setContentView(これは、 R.layout.activity_register); 'この行の' ActivityRegisterViewModel'をクリックすると、問題なくアンドロイドスタジオで開くことができます。 'type =" ir.pishguy.cafealachiqpro.Ui.Register.ActivityMain.Model.ActivityRegisterViewModel "/>' can開きすぎている –

+0

gradleから2行を削除してプロジェクトを実行しようとしましたか? – CodeCameo

関連する問題