2016-09-03 4 views
0

ここで誰かが私にこれがなぜ機能しないのか、どうすれば解決できるのか説明できます。上記のスニペットが動作しないXMLビューファイルビューの属性を持つデータバインディングエラー

 <com.projet.Core.Views.ProfileInfoItemView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      app:setNumber='@{account.posts.intValue()}' 
      app:setTitle="Posts"/> 

から

スニペット。しかし、それは私が中に値をハードコーディングしている場合完璧に動作します。

attrs.xml

<declare-styleable name="ProfileInfoTextView"> 
    <attr name="setNumber" format="integer" /> 
    <attr name="setTitle" format="string" /> 
</declare-styleable> 

スニペットアカウントのクラスからProfileInfoTextViewクラス

private void initialize(Context context, AttributeSet attributeSet) { 
    mRoot = inflate(context, R.layout.custom_profile_info_textview_container,this); 
    mNumberTextView = (TextView) mRoot.findViewById(R.id.custom_profile_info_number_text_view); 
    mTitleTextView = (TextView) mRoot.findViewById(R.id.custom_profile_info_title_text_view); 

    if(attributeSet != null) { 
     TypedArray a = context.getTheme().obtainStyledAttributes(
       attributeSet, 
       R.styleable.ProfileInfoTextView, 
       0, 0); 
     try { 
     mTitleTextView.setText(a.getString(R.styleable.ProfileInfoTextView_setTitle)); 
     String number = getNumber(a.getInt(R.styleable.ProfileInfoTextView_setNumber,1000)); 
     mNumberTextView.setText(number); 
     } finally { 
     a.recycle(); 
     } 
    } 
    } 

スニペットから

public class Account { 
    private Integer posts; 
    public Integer getPosts() { 
     return posts; 
    } 

    public void setPosts(Integer posts) { 
     this.posts = posts; 
    } 
} 

Account.classは、自動生成されたGreenDaoデータクラスです。

私が渡そうとしている値は、整数かintです。どちらも動作しません。私がxmlファイルでハードコードするときだけ。 例外メッセージ

Caused by: java.lang.RuntimeException: Found data binding errors. 
****/ data binding error ****msg:Cannot find the setter for attribute 'app:setNumber' with parameter type java.lang.String on com.projet.Core.Views.ProfileInfoItemView. file:/Users/jemilriahi/ProjectNinjo/app/src/main/res/layout/fragment_my_account.xml loc:81:35 - 81:63 ****\ data binding error **** 

    at android.databinding.tool.processing.Scope.assertNoError(Scope.java:110) 
    at android.databinding.annotationprocessor.ProcessDataBinding.process(ProcessDataBinding.java:76) 
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794) 
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705) 
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91) 
    at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035) 
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176) 
    at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170) 
    at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856) 
    at com.sun.tools.javac.main.Main.compile(Main.java:523) 

誰もが、それが動作しない理由を知っていますか?すべての助けを歓迎します

+0

'account'とその' posts'フィールドのクラスタイプを共有できますか? – yigit

+0

それを追加しました:)しかし、そのクラスにはあまりありません –

答えて

1

あなたのProfileInfoItemViewクラスのようなものは、Stringを受け取るsetNumberメソッドを持っていないようです。あなたのJavaコードではmNumberTextViewsetNumberを子TextViewのように呼びますが、データバインディングにはアクセスできません。

setNumberメソッドをProfileInfoItemViewに作成し、そこにmNumberTextView.setTextと電話すると解決できます。

+0

私はそれを行うことができるか分からなかった。ありがとう! –

関連する問題