Android Gradle Build 显示错误 不允许使用字符串类型(在带有值的"用户名"处)



我的Android Gradle在尝试运行我的应用程序时显示错误。显示

String types not allowed (at 'userName' with value '')

这是等级文件

apply plugin: 'com.android.application'
android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"
    defaultConfig {
        applicationId "xyz.natol.grade12app"
        minSdkVersion 7
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
        }
    }
    repositories {
        maven { url 'http://repo1.maven.org/maven2' }
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
}

而最高级的等级代码是

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
        jcenter()
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

我的字符串XML文件看起来像这个

<resources>
    <string name="app_name">Grade 12</string>
    <string name="insert_reg_no">Your Reg No.</string>
    <string name="check_me">Check me!</string>
    <string name="insert_your_reg_no">Insert your reg no</string>
    <string name="score">Score</string>
    <string name="category">Category</string>
    <string name="not_released">Not released</string>
    <string name="institute">Institute</string>
    <string name="loading">Loading...</string>
    <string name="userName">User Name</string>
    <string name="field_selected">Feild</string>
    <string name="full_name">Full name</string>
    <string name="natural">Natural</string>
    <string name="school">School</string>
    <string name="male">Male</string>
</resources>

使用此字符串的布局TextView看起来像这个

-----------
------
<TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/userName"
                android:id="@+id/userName" />
---------
--------

我不知道该怎么办。有人能在这里暗示一下吗?

检查您的XML布局文件。您可能忘记了id属性中的"+"

您是否尝试将id更改为不同的@+id/user

我刚刚得到了解决方案。。。。问题出在我身上,在colors.xml中,我的样子是这样的

version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#1b5e79</color>
    <color name="colorPrimaryDark">#300F50</color>
    <color name="colorAccent">#FFFFFF</color>
    <color name="userName"></color>
</resources>

我删除了资源标签中的最后一行

<color name="userName"></color>

它起作用了。

相关内容

最新更新