数据绑定;视图标签不正确,Android

时间:2016-03-26 14:24:50

标签: java android android-layout data-binding view

我在数据绑定Android教程中遇到困难。我发现我将数据绑定到视图时遇到问题。

 public class DataView extends FrameLayout {
 private DataViewBinding binding;

 public DataView (Context context, AttributeSet attrs) {
     super(context,attrs);
 }

 @Override
 protected void onFinishInflate()
 {
     super.onFinishInflate();
     binding = DataViewBinding.bind(this);       <---
 }

 @Override
 protected void onAttachedToWindow()
 {
     super.onAttachedToWindow();
     DataSource dataSource = DataSource.get("Data View");
     binding.setDataSource(dataSource);          <---
 } }

data_view.xml

<layout>
    <data>
        <variable
            name="dataSource"
            type="com.example.kaz.simplebindingdemo.DataSource" />
    </data>
    <com.example.kaz.simplebindingdemo.DataView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="16dp"
        tools:showIn="@layout/content_main"
        tools:context=".DataView">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="@{dataSource.message}" />
    </com.example.kaz.simplebindingdemo.DataView>
</layout>

在渲染中我得到了异常:

java.lang.RuntimeException: view tag isn't correct on view:null     at
com.example.kaz.simplebindingdemo.databinding.DataViewBinding.bind(DataViewBinding.java:123)
    at
com.example.kaz.simplebindingdemo.databinding.DataViewBinding.bind(DataViewBinding.java:119)
    at
com.example.kaz.simplebindingdemo.DataView.onFinishInflate(DataView.java:22)
    at
android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:844)
    at
android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:811)    at
android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:515)     at
android.view.LayoutInflater.inflate(LayoutInflater.java:394)

删除绑定声明修复了问题,但我没有自定义视图。 :) 任何

2 个答案:

答案 0 :(得分:0)

像这样改变

<layout
xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools">
    <data>
        <variable
            name="dataSource"
            type="com.example.kaz.simplebindingdemo.DataSource" />
    </data>
    <com.example.kaz.simplebindingdemo.DataView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="16dp"
        tools:showIn="@layout/content_main"
        tools:context=".DataView">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="@{dataSource.message}" />
    </com.example.kaz.simplebindingdemo.DataView>
</layout>

答案 1 :(得分:0)

#!/bin/bash
echo "Hello world"

#####################################################################
#This line will connect to the database and execute the query in Hive
####################################################################

var1=$(beeline --showHeader=false --outputformat=tsv2 -u "jdbc:hive2:XXXXXXXXX" <<EOF
select $2 from $3.$1 where length($2)=(select max(length($2)) from $3.$1) limit 1;
EOF
)


#####################################################################
#This will output the result of the query
####################################################################

echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
echo "We are currently analyzing Table:$1 and Column:$2"
echo "The value wth a maximum length for $1 is $var1"
echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

这些属性应该在顶部的xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" 标签中