Unable to parse XML - Kotlin - android

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.
What went wrong:
Execution failed for task ':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'
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. 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. Even if it was in its correct position, it wouldn't work, because there's nothing called visibilities, it's visibility.
I assume you want to toggle the visibility of the ContraintLayout based on any (assuming boolean) value of the data. 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.

Related

AAPT: error parsing XML: unbound prefix although namespace is defined

I'm trying to transition my app to the action bar. I'm following Google's tutorial. Unfortunately, when trying to build the app, AAPT returns the following error:
menu.xml:6: AAPT: Error parsing XML: unbound prefix
I did some research and found out that this error usually happens when the line xmlns:android="http://schemas.android.com/apk/res/android" isn't included in the XML because then AAPT doesn't know how to interpret the android.xxx tag. However, as you can see from my code, I've included this line in the first node:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"/>
</LinearLayout>
So why doesn't this compile?
You have not declared the app namespace via xmlns:app, but you use it in app:popupTheme. IIRC, there is a quick-fix for that in Android Studio. If not, add xmlns:app="http://schemas.android.com/apk/res-auto" to your root element.

Exception during databinding generation after upgrading to gradle plugin 3.0.1

I upgraded a project to Gradle plugin 3.0.1, but during the databinding classes generation, I get the following error (and the binding classes are not generated):
error: cannot generate view binders java.lang.NullPointerException
at android.databinding.tool.store.SetterStore.getMatchingMultiAttributeSetters(SetterStore.java:642)
at android.databinding.tool.store.SetterStore.getMultiAttributeSetterCalls(SetterStore.java:529)
at android.databinding.tool.BindingTarget.resolveMultiSetters(BindingTarget.java:221)
at android.databinding.tool.LayoutBinder.<init>(LayoutBinder.java:249)
at android.databinding.tool.DataBinder.<init>(DataBinder.java:52)
at android.databinding.tool.CompilerChef.ensureDataBinder(CompilerChef.java:90)
at android.databinding.tool.CompilerChef.sealModels(CompilerChef.java:203)
at android.databinding.annotationprocessor.ProcessExpressions.writeResourceBundle(ProcessExpressions.java:193)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794)
...
After some investigation, it seems that the binding class is correctly generated if I have at most 1 attribute using data binding on a given element in a layout xml. If I add a second one, I get the previous exception.
In the context of my project, the following view causes the error, but unfortunately, in a brand new project, it compiles normally.
<?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">
<data>
<import type="android.view.View"/>
<variable
name="title"
type="String"/>
<variable
name="visible"
type="boolean"/>
</data>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- with either text or visiblility, the project builds, but not with both -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#{title}"
android:visibility="#{visible ? View.VISIBLE : View.GONE}"
/>
</RelativeLayout>
</layout>
Has anyone encountered this issue ?

Error inflating class android.support.design.widget.NavigationView Android

I am able to test my android app on my mobile 5.0 perfectly fine, but testing it on anything lower than 5.0 throws an exception.
"Binary XML file line #16: Error inflating class android.support.design.widget.NavigationView"
My line 16 is basically this
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/main_app_bar"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
I did see other posts about this error, but none of it seems to fix my issue.
This is the full callstack of the error
http://pastebin.com/raw/FaJQFCie
I found it. The error comes from navigation's menu. When I created new project with navigation drawer, Android Studio generates complete work for me. There's a drawable folder named drawable-v21 which stores the icon xml files
I had had the same problem some time ago.
1) Look at your gradle dependencies: you should add library -
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
2) Look at your based colors: you should have
colorPrimary
colorPrimaryDark
colorAccent
3) Look at your layout.nav_header_main. If you will have in the end of error log some message like "Caused by: java.lang.OutOfMemoryError: Failed to" - background image of nav_header_main has a very big resolution or kb weight. Change it and will have success ;)

Using VectorDrawable in layout showing Error parsing XML: duplicate attribute issue

As per the new release of Android studio tools build version 'com.android.tools.build:gradle:1.4.0-beta6' am using VectorDrawable in my layout as follows.
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:id="#+id/list_txt"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableRight="#drawable/ic_arrow_right_16dp"
android:gravity="center_vertical"
android:padding="16dp"
android:textColor="#color/primary_text"
android:textSize="16sp"/>
And in drawable folder generated VectorDrawable as follows:
ic_arrow_right_16dp.xml
<?xml version="1.0" encoding="UTF-8"?>
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="16dp"
android:height="16dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M8.59,16.34l4.58,-4.59 -4.58,-4.59L10,5.75l6,6 -6,6z"/>
</vector>
Issue I am facing
Everything works up to the above steps. But once if i try to build the project I am getting error stating as follows
Error:(7) Error parsing XML: duplicate attribute
Error:Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'F:\adt-bundle-windows-x86\sdk\build-tools\23.0.1\aapt.exe'' finished with non-zero exit value 1
Since I am using VectorDrawable for the first time in my project I really don't know where I am committing mistake and also confused to use which part of gradle build to make use of VectorDrawable's. Any help and solutions will be very helpful me. Thanks in advance.
Note: Currently my buildToolsVersion is "23.0.1"
"Error parsing XML: duplicate attribute" =>
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
Seems to be the duplicate ;)
You are give double Namespace in your xml file
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
Remove 1 Namespace from Your TextView

Data binding expression not compiling

I'm trying out the new data binding library. I have a weird issue where binding the visibility property is not compiling.
This is a simplified version of the xml file:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="header"
type="com.example.EmailHeader" />
</data>
<RelativeLayout ... >
<TextView
...
android:text="#{header.senderName ?? header.senderAddress}"
android:visibility="#{header.hasAttachment ? View.VISIBLE : View.INVISIBLE}" />
</RelativeLayout>
</layout>
I get the follow message when compiling:
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
java.lang.RuntimeException: Found data binding errors.
****/ data binding error ****msg:Identifiers must have user defined types from the XML file. View is missing it
Everything compiles (and works!) when I remove the android:visiblity declaration.
I don't see what I'm missing here
Inside of the data tag you need to also add:
<import type="android.view.View" />
Problem persisted despite adding <import type="android.view.View" /> to my data tag.Finally found the error to be caused by a mismatch of my variable name and object of my POJO class.
This was my data tag:
<data>
<import type="android.view.View" />
<variable
name="employee"
type="com.example.Employee"/>
</data>
and I was using:
<TextView
...
android:text="#{user.lastName}" />
instead of:
<TextView
...
android:text="#{employee.lastName}" />
Forgot to change it after copying code from documentation.
Look out for mistakes like this which are hard to detect for newbies to DataBinding
I faced the exact same error which was caused by the fact that the POJO object was in a library project.
Just upate the build.gradle of the library to enable databinding as well as in the main project:
dataBinding {
enabled = true
}

Categories

Resources