首页 > 解决方案 > Android Studio:代码有重复资源错误,我该如何解决?

问题描述

我刚开始学习 Android Studio。我正在开发一个生日贺卡应用程序。这是我的代码:

<RelativeLayout
    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=".MainActivity">

    <TextView
        android:text="Happy Birthday,Seetha Hari!"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"/>
     <TextView
         android:text="From, Srinitya Suripeddi"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignParentBottom="true"
         android:layout_alignParentRight="true" />

       <ImageView
           android:id="@+id/birthday"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:src ="@drawable/birthday" />
</RelativeLayout>

我得到了:

AGPBI: {"kind":"error","text":"Duplicate resources","sources":[{"file":{"description":"drawable/birthday","path":"/home/hse/AndroidStudioProjects/HappieBirthday/app/src/main/res/drawable/birthday.jpg"}},{"file":{"description":"drawable/birthday","path":"/home/hse/AndroidStudioProjects/HappieBirthday/app/src/main/res/drawable/birthday.xml"}}],"tool":"Resource and asset merger"}

Execution failed for task ':app:mergeDebugResources'.
> [drawable/birthday] /home/hse/AndroidStudioProjects/HappieBirthday/app/src/main/res/drawable/birthday.jpg [drawable/birthday] /home/hse/AndroidStudioProjects/HappieBirthday/app/src/main/res/drawable/birthday.xml: Error: Duplicate resources

运行应用程序时出现重复资源错误。

请帮忙。PS:我的操作系统是 Ubuntu。我不知道这是否有什么不同

标签: androidxml

解决方案


看看 -> 你的可绘制文件夹名称中有一个同名的文件生日.jpg

请删除 1 并重试完整路径为 -> res/drawable/birthday.jpg


推荐阅读