Saturday, 19 November 2016

android - Error:(10) Error parsing XML: duplicate attribute



hi i have got a problem when i was making a navigation drawer.
it show me two :





"Error parsing XML: duplicate attribute"




one of them is about my main layout and another is about my




E:\MyApplication\app\build\intermediates\res\merged\debug\layout\main.xml





and in the down of this two error that show me this:




"Error:Execution failed for task ':app:processDebugResources'.
com.android.ide.common.process.ProcessException: Failed to execute aapt" error too.




and in the preview that say me i have two render error with these subjects





"compilation errors"
and
"Missing classes"




and this is my Main Activity:




package com.example.mehrad.myapplication;


import android.content.Context;
import android.content.SharedPreferences;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;


public class MainActivity extends AppCompatActivity {
private SharedPreferences sharedPreferences;
private DrawerLayout drawerLayout;
private NavigationView navigationView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
new MyShared(this);
new Names("first one");

new Names("second one");
RecyclerView recyclerView=(RecyclerView)findViewById(R.id.rec);
LinearLayoutManager linearLayoutManager=new
LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false);
recyclerView.setLayoutManager(linearLayoutManager);
MyAdapter myAdapter=new MyAdapter(this);
recyclerView.setAdapter(myAdapter);
drawerLayout =(DrawerLayout) findViewById(R.id.dl);
navigationView=(NavigationView)findViewById(R.id.nv);
}

}



and this is my main layout:



     
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"

android:id="@+id/dl"
android:fitsSystemWindows="true"
android:layout_width="wrap_content"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">

android:layout_width="wrap_content"
android:layout_gravity="right"
android:id="@+id/nv"

app:headerLayout="@layout/header"
app:menu="@menu/menu"
android:layout_height="match_parent"/>




and this is my Activity main:



     

xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.mehrad.myapplication.MainActivity">

android:id="@+id/rec"
android:layout_width="match_parent"
android:layout_height="match_parent"

android:clipToPadding="false" />



and this is my app file:



     apply plugin: 'com.android.application'

android {
compileSdkVersion 25

buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.mehrad.myapplication"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}

dependencies {

compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-
core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
}



this is my header:




android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_width="match_parent"

android:src="@drawable/header"
android:id="@+id/image"
android:layout_height="220dp" />



and this is my menu:












help me please


Answer



In this block in your main.xml layout:




        xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/dl"
android:fitsSystemWindows="true"
android:layout_width="wrap_content"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">



You have the attribute xmlns:app twice (see the bottom line). Remove this duplicate attribute and your app should build fine, i.e.



        xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/dl"
android:fitsSystemWindows="true"
android:layout_width="wrap_content"
android:layout_height="match_parent">


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...