Search code examples
javaandroid

Android Gradle Build is showing error String types not allowed (at 'userName' with value '')


My Android Gradle is showing an error when trying to run my app. It's showing:

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

Here is my gradle file

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'
}

And the top level gradle code is:

// 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
}

My Strings XML file looks like this:

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

The layout TextView which uses this string looks like this

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

I don't know what to do. Can any one give me a hint here?


Solution

  • I just got the solution.... The problem was with me, in the colors.xml my looks like this

    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>
    

    And i deleted the last line in my resource tag

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

    And its working.