Android 空白 Activity 构建失败

标签 android build

我刚开始学习 Android 开发。在我的 Android Studio 1.2.2 上,我创建了一个空白 Activity 。根据我的理解,这个空项目应该仍然能够在真实的android设备和模拟器上运行。

但是,当我运行该项目时,我遇到了以下错误:

enter image description here

我检查了我的 Android SDK 管理器并安装了正确的(我相信?)SDK 构建工具。

enter image description here

此外,build.gardle 文件中指定了正确的版本。

enter image description here

这个问题的原因可能是什么?

更新 1

这是项目自动生成的代码。

enter image description here

更新 2

错误信息提示我的activity_myactivity_my.xml的第7行

AGPBI: {"kind":"ERROR","text":"Resource id cannot be an empty string (at \u0027id\u0027 with value \u0027@+id/\u0027).","sourcePath":"C:\Users\Chris Aung\AndroidStudioProjects\MyFirstApp\app\src\main\res\layout\activity_myactivity_my.xml","position":{"startLine":7,"startColumn":17,"startOffset":487,"endColumn":22,"endOffset":492},"original":""}

我的那个文件的第 7 行看起来像这样

enter image description here

最佳答案

只需删除 android:id

我刚刚创建了一个空白 Activity 项目,这里是创建的没有错误的默认布局:

<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">

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

</RelativeLayout>

关于Android 空白 Activity 构建失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31445043/

相关文章:

android - 将实时视频从安卓摄像头流式传输到服务器

android - 如何在android中实现双击表面 View

java - Maven 尝试在 `validate` 阶段下载多模块依赖

Java:如何故意使 Jenkins 构建失败?

c# - "Build"构建我的项目,"Build Solution"没有

java - 是否可以为maven + jenkins打包过程编写 "local"脚本/hook?

java - 如何忽略 XML SAX PARSING 中的相似标签

Android 用户界面 ListView

android - Eclipse 无法打开android 项目?

java - Maven 插件签署特定文件