hello world application

时间:2015-05-27 06:37:35

标签: android macos android-studio ide

我正试图在youtube上的这个thenewboston tutorial之后在Android Studio中构建基本的hello world应用程序。我创建了一个包含所有默认设置的新项目。 (Android API 14:Android 4.0(IceCreamSandwich))

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

错误:(7,17)

  

资源ID不能是空字符串('id'的值为'@ + id /')。

错误:任务':app:processDebugResources'执行失败。

  

com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:处理'命令'/Users/abhinavmoudgil95/Library/Android/sdk/build-tools/22.0.1/aapt' '完成了非零退出值1

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

以下是规格:

  • Android Studio 1.2.1.1
  • 在Macbook Pro OS X上运行:10.10.3(Yosemite)
  • BuildToolsVersion:22.0.1

项目文件:

activity_main.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=".MainActivity"
    android:id="@+id/">

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

</RelativeLayout>

build.gradle(Project:MyApplication)

 apply plugin: 'com.android.application'
android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.example.abhinavmoudgil95.myapplication"
        minSdkVersion 14
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.1.1'
}

build.grade(Module:app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.example.abhinavmoudgil95.myapplication"
        minSdkVersion 14
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.1.1'
}

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

2 个答案:

答案 0 :(得分:1)

稍作修改:

您未在{strong> RelativeLayout

中的android:id="@+id/"中定义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>

答案 1 :(得分:1)

当您为xml中的任何android:id定义view个预设时,必须提供这样的唯一ID,因此您不能像在xml中那样留下空白ID。

删除此行:

android:id="@+id/"

OR

添加一些唯一的ID名称:

android:id="@+id/relativeLayout"
相关问题