Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android数据绑定xml重复属性_Android_Xml_Android Layout_Data Binding_Android Databinding - Fatal编程技术网

Android数据绑定xml重复属性

Android数据绑定xml重复属性,android,xml,android-layout,data-binding,android-databinding,Android,Xml,Android Layout,Data Binding,Android Databinding,我最近开始开发一个使用数据绑定的android应用程序。我现在的问题是,由于以下错误,我无法运行该应用程序: Error:(10) Error parsing XML: duplicate attribute 错误发生在使用数据绑定的每个文件中(我使用的是片段)。我在谷歌上搜索了3个小时,却找不到解决办法 build.gradle: apply plugin: 'com.android.application' android { dexOptions { preDe

我最近开始开发一个使用数据绑定的android应用程序。我现在的问题是,由于以下错误,我无法运行该应用程序:

Error:(10) Error parsing XML: duplicate attribute
错误发生在使用数据绑定的每个文件中(我使用的是片段)。我在谷歌上搜索了3个小时,却找不到解决办法

build.gradle:

apply plugin: 'com.android.application'

android {
    dexOptions {
        preDexLibraries = false
        javaMaxHeapSize "2g"
    }
    compileSdkVersion 23
    buildToolsVersion "23.0.3"
    defaultConfig {
        applicationId "at.blacktasty.schooltoolmobile"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dataBinding {
        enabled = true
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile files('libs/eneter-messaging-android-7.0.1.jar')
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.android.support:support-v4:23.4.0'
    testCompile 'junit:junit:4.12'
}
fragment_tests.xml:

<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="layout.tests">

    <data>
        <variable
            name="deadline"
            type="at.blacktasty.schooltoolmobile.viewmodel.STViewModel"/>
    </data>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ListView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/list_tests"
            android:entries="@{deadline.deadline}"/>
    </LinearLayout>
</layout>
以及发生错误的xml文件(debug\layout\fragment\u tests.xml)。布局宽度和布局高度标记为错误:

    <LinearLayout
        android:layout_width="match_parent" 
        android:layout_height="match_parent" android:tag="layout/fragment_tests_0" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="layout.tests">
    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/list_tests"
        android:tag="binding_1"               />
</LinearLayout>

我真的希望有人能帮我

编辑:此处显示STViewModel类:

public class STViewModel extends BaseObservable {
    private ObservableArrayList<Deadline> m_deadline = new ObservableArrayList<>();

    @Bindable
    public ObservableArrayList<Deadline> getDeadline(){
        return m_deadline;
    }

    public void setDeadline(ObservableArrayList<Deadline> value){
        m_deadline = value;
        notifyPropertyChanged(BR.deadline);
    }
}
公共类STViewModel扩展了BaseObservable{
private ObserverArrayList m_deadline=新ObserverArrayList();
@装订的
公共列表getDeadline(){
返回m_截止日期;
}
公共作废设置截止日期(ObservableArrayList值){
m_截止日期=值;
notifyPropertyChanged(BR.截止日期);
}
}
您应该定义

android:orientation 
属性到线性布局

你的直线布局应该是这样的

  <LinearLayout
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:tag="layout/fragment_tests_0" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"
    tools:context="layout.tests">
   <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/list_tests"
        android:tag="binding_1" />
  </LinearLayout>

我刚刚找到了解决方案。我只需要从
定义中删除布局宽度和布局高度

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

而不是

<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="layout.tests">

通过删除
字段中的所有属性,即保持其

<layout>

  <data>

    <variable
        name=""
        type="" />

  </data>

  <LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


  </LinearLayout>
</layout>

确保
xmlns:android
不会自动添加到
和实际布局
视图组中:

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

    <android.support.v4.widget.DrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        ...>
    </android.support.v4.widget.DrawerLayout>
</layout>

从任意一个位置删除
xmlns:android

我使用了两次“xmlns”属性,这就是接收错误的原因

<?xml version="1.0" encoding="utf-8"?>
    <layout xmlns:android="http://schemas.android.com/apk/res/android"
             xmlns:app="http://schemas.android.com/apk/res-auto">
    <android.support.constraint.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/offwhite">

用下面的代码修复

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.constraint.ConstraintLayout 
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/offwhite">

删除行

android:layout_width="match_parent"
android:layout_height="match_parent" 

在xml中的布局标记下。它将导致生成错误。

您是否在
STViewModel
中有
deadline
吗?是的,deadline在STViewModel中,我已将该类添加到我的问题中。尝试更改其名称,它可能会解决您的问题我刚刚发现问题所在。解决方案在下面的答案中。可能的重复有时您需要查看闭包。解决方案总是隐藏在问题中。在我的例子中,我有重复的xmlns:declaration。对我有效。谢谢在我的情况下,
xmlns:android
xmlns:app
,但是谢谢。对我也有用
android:layout_width="match_parent"
android:layout_height="match_parent"