【问题标题】:Build failed due to invalid symbol由于符号无效,构建失败
【发布时间】:2014-11-26 08:23:42
【问题描述】:

我的drawables文件夹中有一些图像,其中一个称为“最终”。当我运行我的项目时,我收到以下错误:

Error:Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\android\adt-bundle-windows-x86_64-20140702\sdk\build-tools\android-4.4W\aapt.exe package -f -   -no-crunch -I C:\android\adt-bundle-windows-x86_64-20140702\sdk\platforms\android-20\android.jar -M     C:\Users\SHREYA     BISHT\AndroidStudioProjects\staymax\app\build\intermediates\manifests\full\debug\AndroidManifest.xml -S C:\Users\SHREYA BISHT\AndroidStudioProjects\staymax\app\build\intermediates\res\debug -A C:\Users\SHREYA BISHT\AndroidStudioProjects\staymax\app\build\intermediates\assets\debug -m -J C:\Users\SHREYA BISHT\AndroidStudioProjects\staymax\app\build\generated\source\r\debug -F C:\Users\SHREYA BISHT\AndroidStudioProjects\staymax\app\build\intermediates\res\resources-debug.ap_     --debug-mode --custom-package com.appt.shreyabisht.staymax -0 apk
Error Code:
1
Output:
res\drawable-hdpi-v4\final.jpg:0: error: invalid symbol: 'final'

这是我已经完成的: 1.删​​除图像并使用不同的名称重新导入,并在我使用图像的 xml 文件中进行了更改。同样的错误。 2.运行无效并重新启动。同样的错误 3.运行干净的项目。同样的错误。

请提出建议。

activity_main:

<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" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
android:background="@drawable/backw"
android:id="@+id/lay">

<TextView android:text="StayMax" android:layout_width="wrap_content"
    android:textSize="30dp"
    android:textStyle="bold"


    android:layout_height="wrap_content"
    android:id="@+id/textView"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true" />

<Button
    android:layout_width="80dp"
    android:layout_height="40dp"
    android:text="@string/sign_in"


    android:id="@+id/btn_first"
    android:layout_below="@+id/textView"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="87dp" />

</RelativeLayout>

这是第二页:

<TextView android:text="@string/title_signin" android:layout_width="wrap_content"
    android:textSize="15dp"
    android:layout_height="44dp"

 />


<Space
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0.33" />

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:layout_width="120dp"
        android:layout_height="wrap_content" />

</LinearLayout>

<LinearLayout
    android:layout_width="wrap_content"
    android:orientation="vertical" android:layout_height="wrap_content">

</LinearLayout>

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/user"
    />

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Password :"/>

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Sign In"
    android:id="@+id/sign"
    android:layout_gravity="center_horizontal" />


</LinearLayout>

这是第三页:

<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"
android:background="@drawable/backgr"
tools:context="com.appt.shreyabisht.staymax.hotel_home"

>

<TextView android:text="Welcome to Ayaya"
     android:layout_width="wrap_content"

  android:textSize="15dp"

    android:textColor="#FFFFFF"
    android:layout_height="wrap_content"
    android:id="@+id/textView2"
    android:layout_centerHorizontal="true"
    android:layout_gravity="center_horizontal"
    android:layout_weight="0.35" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/room_service"
    android:textSize="15dp"
    android:id="@+id/btn_service"
    android:layout_toStartOf="@+id/textView2"
    android:layout_marginBottom="104dp"
    android:background="#a1ef7c2d"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hotel_amenities"
    android:textSize="15dp"
    android:id="@+id/btn_amn"
    android:background="#a1ef7c2d"
    android:layout_toEndOf="@+id/btn_service"
    android:layout_toStartOf="@+id/button6"
    android:layout_alignTop="@+id/btn_service"
    android:layout_toRightOf="@+id/btn_service" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/trans"
    android:textSize="15dp"
    android:id="@+id/btn_trans"
    android:background="#a1ef7c2d"
    android:layout_toEndOf="@+id/btn_amn"
    android:layout_alignTop="@+id/btn_amn"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true" />


</RelativeLayout>

对于接下来的三页,我正在尝试设置标签滚动视图(它们是子菜单)

所以第一个子菜单: activity_amn_menu.xml

<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

</RelativeLayout>

第二个子菜单: activity_trans_menu.xml

<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" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.appt.shreyabisht.staymax.trans_menu">

<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

</RelativeLayout>

第三个菜单: activity_service_menu.xml

<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" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.appt.shreyabisht.staymax.service_menu"
>


<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/dining"
    android:id="@+id/button"
    android:textSize="15dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Laundry"
    android:id="@+id/button2"
    android:textSize="15dp"
    android:layout_alignParentBottom="true"
    android:layout_toRightOf="@+id/button"
    android:layout_toEndOf="@+id/button" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="15dp"
    android:text="House Keeping"
    android:id="@+id/button3"
    android:layout_alignParentBottom="true"
    android:layout_toRightOf="@+id/button2"
    android:layout_toEndOf="@+id/button2" />
</RelativeLayout>

注意:这个项目一直运行到昨天,今天我决定加入 viewpager,这样它们现在可能无法在你的机器上运行。

【问题讨论】:

    标签: android error-handling


    【解决方案1】:

    final是Java保留字,你不能这样命名你的图片,选择其他名称,任何其他名称,但不要选择任何保留字如staticpublicintexception、...等。

    here 中的 Java 保留字列表。

    【讨论】:

    • 我意识到这一点,然后我删除了文件。它不再在我的drawables中,我也不再在我的xml中使用“final”这个词。那为什么会出错呢?
    • @shrbisht 去你的任何活动并尝试输入R.id.final,如果你找到它,那么,你必须在你的应用程序的其他地方忘记它,如果你没有,只需重新启动 eclipse和adb然后看看错误是否依然存在
    • @muhameed 你能再解释一下吗? r.id.final 的作用是什么? R.id.final 应该在所有 java 类中?
    • @shrbisht 不,但是项目中存在的资源文件(/gen/R)包含项目中所有资源的ID,所以,如果你的图像“最终”仍然存在于项目中它会在那里,所以,如果你在那里找到它,这意味着它仍然存在于你的项目中的其他地方,你必须删除它,如果你没有在那里找到它,那可能是因为灵活性的泄漏eclipse 然后你所要做的就是重启eclipse和adb
    • 好的,谢谢。知道了。我使用android studio,有什么区别吗?我还看到在我的项目中有“R”的地方,比如 R.id.,它的红色并表示无法解析符号 R。
    【解决方案2】:

    @Muhammed 感谢您今天提供的所有帮助。我通过清理项目然后执行无效并重新启动解决了上述问题。我今天早些时候这样做了,但我想我没有执行清理并一个接一个地重新启动以查看结果。

    【讨论】:

      猜你喜欢
      • 2017-06-08
      • 1970-01-01
      • 1970-01-01
      • 2019-11-13
      • 2021-10-20
      • 2019-09-24
      • 2012-08-21
      • 2020-12-22
      • 1970-01-01
      相关资源
      最近更新 更多