缺少 Android Activity XML 资源标识符

标签 android xml build

当我尝试运行我的应用程序并且 Gradle Build 正在运行时,我收到以下错误:

No resource identifier found at attribute 'context' in package 'com.protonmail.fabian.schneider.aim'

(在开始 Activity 中) (当双击错误时,它会将我带到 RelativeLayout 标签。但是文件中没有错误; 当我双击调试文件夹中同一文件中的错误时,所有 URL 都是红色的,因此可能是错误...)

过去几周它运行良好,但三天前它停止工作了,当时我对 Activity 的元素重新排序。

我尝试清理和构建,重新启动 android studio。我还尝试更改 xmlns:android,app,tools 中的 URL(因为我在研究时发现了这一点)- 但没有任何帮助。

如果有帮助:这是 Gradle 控制台的输出:

Executing tasks: [:app:clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :app:assembleDebug]

Configuration on demand is an incubating feature.
Incremental java compilation is an incubating feature.
:app:clean
:app:buildInfoDebugLoader
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:prepareComAndroidSupportAnimatedVectorDrawable2421Library
:app:prepareComAndroidSupportAppcompatV72421Library
:app:prepareComAndroidSupportDesign2421Library
:app:prepareComAndroidSupportRecyclerviewV72421Library
:app:prepareComAndroidSupportSupportCompat2421Library
:app:prepareComAndroidSupportSupportCoreUi2421Library
:app:prepareComAndroidSupportSupportCoreUtils2421Library
:app:prepareComAndroidSupportSupportFragment2421Library
:app:prepareComAndroidSupportSupportMediaCompat2421Library
:app:prepareComAndroidSupportSupportV42421Library
:app:prepareComAndroidSupportSupportVectorDrawable2421Library
:app:prepareDebugDependencies
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:generateDebugBuildConfig
:app:generateDebugResValues
:app:generateDebugResources
:app:mergeDebugResources
:app:processDebugManifest
:app:processDebugResources
AGPBI: {"kind":"error","text":"No resource identifier found for attribute \u0027context\u0027 in package \u0027com.protonmail.fabian.schneider.aim\u0027","sources":[{"file":"/home/faebl/Programming/apps/android/AIM/app/src/main/res/layout/activity_aim_start.xml","position":{"startLine":1}}],"original":"","tool":"AAPT"}
/home/faebl/Programming/apps/android/AIM/app/build/intermediates/res/merged/debug/layout/activity_aim_start.xml:2: error: No resource identifier found for attribute 'context' in package 'com.protonmail.fabian.schneider.aim'



 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.process.ProcessException: Failed to execute aapt

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 1.695 secs

您能否推荐一些解决该问题的方法?

这是有问题的 XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/lib/com.protonmail.fabian.schneider.aim"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.protonmail.fabian.schneider.aim.AIM_start">

    <android.support.v7.widget.Toolbar
        android:id="@+id/my_toolbar"
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.ActionBar"
        />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="AIM OS"
        android:textIsSelectable="false"
        android:textSize="30dp"
        android:textAlignment="center"
        android:textColor="#0a0a53"
        android:id="@+id/textView"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:contentDescription="Analysis of Interplanetary Magnetic-Field Data" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Start AIM"
        android:id="@+id/start_AIM"
        android:layout_marginTop="24dp"
        android:layout_x="112dp"
        android:layout_y="122dp"
        android:width="200dp"
        android:layout_below="@+id/textView"
        android:layout_centerHorizontal="true"
        android:background="@drawable/button_custom_rect"
        android:gravity="center_horizontal|center_vertical"/>

    <Button
        android:text="Stop AIM"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/stop_AIM"
        android:layout_marginTop="11dp"
        android:layout_x="148dp"
        android:layout_y="226dp"
        android:width="200dp"
        android:layout_below="@+id/start_AIM"
        android:layout_alignLeft="@+id/start_AIM"
        android:layout_alignStart="@+id/start_AIM"
        android:background="@drawable/button_custom_rect"
        android:gravity="center_horizontal|center_vertical"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:id="@+id/lbl_output"
        android:layout_x="139dp"
        android:layout_y="372dp"
        android:layout_marginBottom="10dp"
        android:layout_above="@+id/statusView"
        android:layout_centerHorizontal="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:id="@+id/statusView"
        android:textSize="25dp"
        android:layout_marginBottom="13dp"
        android:layout_x="138dp"
        android:layout_y="435dp"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/stop_AIM"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="79dp"
        android:id="@+id/lbl_actualConfig"
        android:textSize="18sp"
        android:textColor="@android:color/black" />

    <Button
        android:text="..."
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:id="@+id/settings"
        android:onClick="sendMessage"
        android:background="@drawable/button_custom_round"
        android:gravity="center_vertical|center_horizontal"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />


</RelativeLayout>

最佳答案

好吧,我终于通过试错解决了这个错误。

我真的没有解释,但它确实有效。

我删除了带有 xmlns:tools 和 tools:context 的行,因为稍后在 xml 中的任何地方都不需要它们。 删除它们后,我清理并重建了项目,它再次运行。

希望对大家有所帮助。 (如果有人知道为什么它有帮助,请发表评论:))

关于缺少 Android Activity XML 资源标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41764665/

相关文章:

java - 如何将 Retrofit 响应映射到数据模型类?

java : xml child not getting deleted using removeChild

Ant exec 结果属性不起作用

删除 ACRA 后,android 找不到符号类 RequiresApi

java - Android 旋转器与对象

java - Firebase 之间的区别 putBytes 或 putfile 哪个上传速度快?

xml - 使用 Logstash 解析来自 Filebeat 的 XML 数据

java - 无法解析 XStream 类

javascript - 监控 grunt-contrib-watch 的子任务

android - Android进度栏未显示