【问题标题】:Error:(10) Error parsing XML: duplicate attribute错误:(10) 解析 XML 时出错:重复属性
【发布时间】:2018-07-24 02:42:55
【问题描述】:

您好,我在制作导航抽屉时遇到了问题。 它给我看两个:

“解析 XML 时出错:重复属性”

其中一个是关于我的主要布局,另一个是关于我的

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

在这两个错误的后面,告诉我这个:

“错误:任务 ':app:processDebugResources' 执行失败。 com.android.ide.common.process.ProcessException: Failed to execute aapt" 错误。

在预览中说我这些主题有两个渲染错误

“编译错误” 和 “缺课”

这是我的主要活动:

包 com.example.mehrad.myapplication; 导入android.content.Context; 导入 android.content.SharedPreferences; 导入 android.support.v4.widget.DrawerLayout; 导入android.support.v7.app.AppCompatActivity; 导入android.os.Bundle; 导入 android.support.v7.widget.LinearLayoutManager; 导入 android.support.v7.widget.RecyclerView; 导入 android.view.LayoutInflater; 公共类 MainActivity 扩展 AppCompatActivity { 私人共享偏好共享偏好; 私人抽屉布局抽屉布局; 私人导航视图导航视图; @覆盖 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); 设置内容视图(R.layout.main); 新的我的共享(这个); 新名称(“第一个”); 新名称(“第二个”); RecyclerView recyclerView=(RecyclerView)findViewById(R.id.rec); 线性布局管理器线性布局管理器=新 LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false); recyclerView.setLayoutManager(linearLayoutManager); 我的适配器我的适配器=新的我的适配器(这个); recyclerView.setAdapter(myAdapter); 抽屉布局=(抽屉布局)findViewById(R.id.dl); 导航视图=(导航视图)findViewById(R.id.nv); } }

这是我的主要布局:

     <?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"
            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">
            <include layout="@layout/activity_main"/>
            <android.support.design.widget.NavigationView
            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"/>

    </android.support.v4.widget.DrawerLayout>

这是我的主要活动:

     <?xml version="1.0" encoding="utf-8"?>
     <LinearLayout 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="com.example.mehrad.myapplication.MainActivity">

     <android.support.v7.widget.RecyclerView
         android:id="@+id/rec"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:clipToPadding="false" />
     </LinearLayout>

这是我的应用文件:

     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'
}

这是我的标题:

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ImageView
            android:layout_width="match_parent"
            android:src="@drawable/header"
            android:id="@+id/image"
            android:layout_height="220dp" />
    </LinearLayout>

这是我的菜单:

<?xml version="1.0" encoding="utf-8"?>
     <menu xmlns:android="http://schemas.android.com/apk/res/android">
         <item android:id="@+id/favorite" android:title="list"/>
         <item android:id="@+id/about" android:title="about us"/>
         <item android:id="@+id/exit" android:title="exit"/>
     </menu>

请帮帮我

【问题讨论】:

    标签: android


    【解决方案1】:

    就我而言,这是因为我为layout 标签(用于数据绑定)指定了高度和宽度。这些属性应该只为实际持有项目的孩子指定。

    【讨论】:

      【解决方案2】:

      在您的 main.xml 布局中的此块中:

      <android.support.v4.widget.DrawerLayout
              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">
      

      你有两次xmlns:app 属性(见底线)。删除此重复属性,您的应用程序应该可以正常构建,即

      <android.support.v4.widget.DrawerLayout
              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">
      

      【讨论】:

      • 非常感谢,但现在这给了我另一个主题“错误:(10)在包'com.example.mehrad.myapplication'中找不到属性'headerLayout'的资源标识符”
      • 和这个“错误:(10)在包'com.example.mehrad.myapplication'中找不到属性'menu'的资源标识符”
      • 您有名为res/layout/header.xmlres/menu/menu.xml 的文件吗?
      【解决方案3】:

      layout 标记中删除以下行

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-11-19
        • 2019-01-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多