简体   繁体   English

无法解析 XML - Kotlin

[英]Unable to parse XML - Kotlin

在此处输入图像描述

Caused by: 
org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A
failure occurred while executing com.android.build.gradle.internal.res.ParseLibraryResourcesTask$ParseResourcesRunnable

Other error codes其他错误代码

FAILURE: Build completed with 2 failures.

1: Task failed with an exception. 1:任务因异常而失败。

  • What went wrong: Execution failed for task ':app:parseDebugLocalResources'.出了什么问题:任务 ':app:parseDebugLocalResources' 执行失败。

A failure occurred while executing com.android.build.gradle.internal.res.ParseLibraryResourcesTask$ParseResourcesRunnable Failed to parse XML file '/home/shinto/Documents/PostMethodTrialChecking/HelpIntern/app/build/intermediates/packaged_res/debug/layout/fragment_signup.xml' A failure occurred while executing com.android.build.gradle.internal.res.ParseLibraryResourcesTask$ParseResourcesRunnable Failed to parse XML file '/home/shinto/Documents/PostMethodTrialChecking/HelpIntern/app/build/intermediates/packaged_res/debug/layout/fragment_signup.xml'

fragment_signup.xml

<data>
    <variable
        name="users"
        type="com.shinto.helpintern.MainViewModel" />
</data>
android:visibilities="@{users.}"
<androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/progBar"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

Your XML code is wrong.您的 XML 密码错误。 And as the error suggests, compiler expects a < , means an opening tag.正如错误所暗示的那样,编译器需要一个< ,表示一个开始标记。 Why?为什么?

Because this line android:visibilities="@{users.}" is misplaced and isn't in any tag.因为这一行android:visibilities="@{users.}"放错了位置,不在任何标签中。 Even if it was in its correct position, it wouldn't work, because there's nothing called visibilities , it's visibility .即使它是正确的 position,它也不起作用,因为没有什么叫做visibilities ,它是visibility

I assume you want to toggle the visibility of the ContraintLayout based on any (assuming boolean) value of the data.我假设您想根据数据的任何(假设为布尔值)值切换ContraintLayout的可见性。 To do that, change your code as:为此,请将您的代码更改为:

<data>
    <import type="android.view.View"/>
    <variable
        name="users"
        type="com.shinto.helpintern.MainViewModel" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/progBar"
    android:visibility="@{users.yourValue? View.GONE : View.VISIBLE}"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

This will toggle the layout's visibility based on the value of your model.这将根据您的 model 的值切换布局的可见性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM