Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
hello world应用程序中的Android studio生成错误_Android_Macos_Android Studio_Ide - Fatal编程技术网

hello world应用程序中的Android studio生成错误

hello world应用程序中的Android studio生成错误,android,macos,android-studio,ide,Android,Macos,Android Studio,Ide,我正试图在Android Studio中构建基本的hello world应用程序,下面是youtube上的NewBoston。我用所有默认设置创建了一个新项目。(安卓API 14:安卓4.0(冰淇淋三明治)) 当我尝试运行应用程序时,出现以下错误: 错误:(7,17) 资源id不能为空字符串(位于值为“@+id/”的“id”处) 错误:任务“:app:processDebugResources”的执行失败 com.android.ide.common.process.ProcessExcepti

我正试图在Android Studio中构建基本的hello world应用程序,下面是youtube上的NewBoston。我用所有默认设置创建了一个新项目。(安卓API 14:安卓4.0(冰淇淋三明治))

当我尝试运行应用程序时,出现以下错误:

错误:(7,17)

资源id不能为空字符串(位于值为“@+id/”的“id”处)

错误:任务“:app:processDebugResources”的执行失败

com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:process'command'/Users/abhinavmoudgil95/Library/android/sdk/build tools/22.0.1/aapt''以非零退出值1结束

可以查看错误的屏幕截图。

规格如下:

  • Android Studio 1.2.1.1
  • 在MacBookPro OS X上运行:10.10.3(约塞米蒂)
  • BuildTools版本:22.0.1
项目文件:

activity_main.xml


build.grade(模块:应用程序)


我对android开发完全陌生。所以请尽量简单地回答

稍微修改一下:

您没有在
android:id=“@+id/”
RelativeLayout中定义id

<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:id="@+id/layout">

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

</RelativeLayout>

当您在xml中定义任何
视图的
android:id
属性时,必须提供这样一个唯一的id,所以您不能像在xml中那样保留空白id

删除此行:

android:id="@+id/"

添加一些唯一的id名称:

android:id="@+id/relativeLayout"

删除这行android:id=“@+id/”或将android:id=“@+id/relativeLayout”从xml中更改。出于好奇,问一个问题:我是否必须在每个项目中都这样做?为什么xml中的默认代码不起作用?当您使用android:id=“@+id/”时,您必须定义唯一id,否则不要提及此属性。它帮助您通过唯一id从代码中的xml访问特定组件id@Abhinav如果双击“设计”视图,它将自动将此行添加到根布局中。@NarenderNishad抱歉,我找不到设计视图。你能详细说明一下吗?非常感谢。我希望我也能投票支持你的答案:)
<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:id="@+id/layout">

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

</RelativeLayout>
android:id="@+id/"
android:id="@+id/relativeLayout"