Android Studio error in build - Cause: startElement.getAttributeByName(QName("name")) must not be null

Viewed 2565

I want to create a spinner widget, and I added this to string.xml:

    <string-array name="options">
        <item>All Tasks</item>
        <item>Today's Tasks</item>
        <item>Tomorrow's Tasks</item>
        <item>Archived Tasks</item>
    </string-array>

and I adapted it:

ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
                R.array.options, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        spinner.setAdapter(adapter);

and I got a build error:

Cause: startElement.getAttributeByName(QName("name")) must not be null

How can I solve this?

3 Answers

Special character like apostrophe(') are not allowed in xml directly Use can use escape sequences to get the desired result.

Replace: Today's by Today \ 's

Use a \ backslash symbol before apostrophe '

In String.xml

replace 'String which you have entered' to String which you have entered

or simply remove ' ' these

Try replacing :

ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
            R.array.options, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    spinner.setAdapter(adapter);

By :

final String options = getResources().getStringArray(R.array.options);
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, 
android.R.layout.simple_spinner_dropdown_item, options);
spinner.setAdapter(adapter);

Please let me know if this works. Thank you

Related