Issue
I was making a simple calculator app design and mid-way I decided to test it. I though it was going to run without any errors however it shows an error like this:
C:\Users\mahir\AndroidStudioProjects\SimpleCalculatorappforstudents\app\src\main\res\layout\activity_main.xml:5: error: duplicate attribute.
C:\Users\mahir\AndroidStudioProjects\SimpleCalculatorappforstudents\app\src\main\res\layout\activity_main.xml: error: file failed to compile.
I have searched google to solve this problem however I am unable to arrive at a solution. This is my XML file:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="@+id/number5"
android:layout_width="81dp"
android:layout_height="72dp"
android:text="5"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.336"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.881" />
<Button
android:id="@+id/number4"
android:layout_width="81dp"
android:layout_height="72dp"
android:text="4"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.027"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.881" />
<Button
android:id="@+id/number7"
android:layout_width="81dp"
android:layout_height="72dp"
android:text="7"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.027"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
<Button
android:id="@+id/number8"
android:layout_width="81dp"
android:layout_height="72dp"
android:text="8"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.336"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
<Button
android:id="@+id/number1"
android:layout_width="81dp"
android:layout_height="72dp"
android:text="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.027"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.748" />
<Button
android:id="@+id/brackets"
android:layout_width="81dp"
android:layout_height="72dp"
android:text="( )"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.951"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.749" />
<Button
android:id="@+id/number9"
android:layout_width="81dp"
android:layout_height="72dp"
android:text="9"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.633"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
<Button
android:id="@+id/number6"
android:layout_width="81dp"
android:layout_height="72dp"
android:text="6"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.633"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.881" />
<Button
android:id="@+id/multiply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Multiply"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.346"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.631" />
<Button
android:id="@+id/divide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Divide"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.972"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.631" />
<Button
android:id="@+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.027"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.631" />
<Button
android:id="@+id/number2"
android:layout_width="81dp"
android:layout_height="72dp"
android:text="2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.336"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.749" />
<Button
android:id="@+id/number3"
android:layout_width="81dp"
android:layout_height="72dp"
android:text="3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.633"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.749" />
<Button
android:id="@+id/history"
android:layout_width="98dp"
android:layout_height="45dp"
android:background="@drawable/roundbutton"
android:text="History"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.968"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.008" />
<Button
android:id="@+id/subtract"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Subtract"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.661"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.631" />
I would gladly accept any help on this error. I am a beginner in Android development and I am using the latest Android Studio.
Solution
You have added the same line twice as an attribute within the ConstraintLayout
.
xmlns:android="http://schemas.android.com/apk/res/android"
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" (1st time)
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android" (2nd time)
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
Answered By - Prince Dholakiya
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.