Resource name must Start with a letter - android

I am having this issue when I am having file with name 01a.png under res/drawable.
The error looks like:
Error: The resource name must start with a letter
I am using build:gradle:2.1.2 and SDK version 24.
Any solution to fix this without changing filename and without degrading SDK version?

change the name of the resources, it MUST start with a letter

Imagname must starts with a letter so change the image name

Resources are located on the left in your Android Studio.
Project > app > res > values.. you'll find your resources there. Android studio will commonly mark the incorrect syntax with RED text

In My Case when the string key name got removed from string.xml so I got this error,
for example:
<string name="">Submit Order</string>
after putting back string key name like below, it's working fine
<string name="label_submit_order">Submit Order</string>

Related

Why does Android Studio give me warnings to add code that Android Studio already added automatically?

As soon as I drag/drop a button from Palette into the XML file, Android Studio gives me the following error when I click on "Show Warnings and Errors":
Message: [I18N] Hardcoded string "Button", should use `#string` resource Suggested Fixes:
- Extract string resource
- Suppress: Add tools:ignore="HardcodedText" attribute
Inside the Button code in Text the following Android Studios enters itself automatically when I dragged/dropped button into XML file:
android:text="Button"
Do I just always have to click "Suppress" choice because I don't know what they want me to change for "Extract String Resource" choice. Or is it asking me to change Android Studio's code that it sets itself automatically?
You can do this instead of suppressing:
Add a String resource in res/values/strings.xml:
<string name="button_label">Button</string>
Set the above resource as text for your Button:
android:text="#string/button_label"
It is not an Error, this is just Warning that say you should use string resources, but not hardcoded strings in your code. But you can use hadrdcoded Strings and all will work fine.
Using String resources simplifies your life. For example when you want to localize your app. See screenshot.
using string resources
You can set string res. to TextView.Text, then create few android resource directories with names values, values-ru, values-uk etc.
In this direcroties you should create file strings.xml for each.
and Override your string like
<string name="message"> Message </string> in values
<string name="message"> Сообщение </string> in values-ru etc.
Now if you change your device language, from en to ru , in your app in textView will be written "Сообщение"
It is also useful in several other cases.
Message: [I18N] Hardcoded string "Button", should use #string
resource
Suggested Fixes:
Extract string resource
You should always pick string from string.xml in res/values/strings.xml. It's not the right way to hard code the strings, putting it into the string.xml file helps for localization in future.
Add tools:ignore="HardcodedText" attribute
When you use tools, it doesn't actually set the text to view, but it just shows you in preview window as how it visually appears, when you run the app, you won't the text added in tools.

Android Studio error message I18n

I got an error message that says:
[I18N] Hardcoded string "Today - Sunny - 78/67", should use #string
resource.
How can this error be resolved?
The line of code is: android:text="Today - Sunny - 78/67"
i18n is an abbreviation for internationalization. Android Studio is just giving you a hint that the way you are setting the text won't allow you to easily translate it.
Instead you should put your string in a strings.xml file within the res/values folder:
<resources>
<string name="my_string">Today - Sunny - 78/67</string>
</resources>
You then reference that string on your TextView like this:
android:text="#string/my_string"
This would allow you to make another file for spanish strings, res/values-es/strings.xml that you could add a translation to:
<resources>
<string name="my_string">Hoy - Soleado - 78/67</string>
</resources>
And then that string will automatically get picked for your TextView if the user's locale language is Spanish.
It's implying that you should not explicitly write your text in your XML. You should use the /Values/Strings.xml to hold your string values.
Take a look through the folders on the left side, for values. The file is already there. You just need to add your string to it.
For the record, this doesn't normally generate an error of the "I'm gonna crash now" variety. It's usually just a warning.
you can put mouse on problems line and use android studio hot key - alt+enter. After that you can choose "Extract string resource"
Sory fo my bad english =)

Auto Generate #String reference in Android Studio

I know that this is possible in eclipse by following the advice here: Android: resource String automatic generation
But I can't seem to find if this is possible in android studio yet. Anybody know how to do this?
Basically I would like to take a hardcoded string and auto create a #string reference in my main values.xml or strings.xml.
Alt+Enter, Extract String Resource while the caret is inside the hardcoded string:
The same should work in XML files as well, and it does work in IntelliJ IDEA, but seems to be broken in the current version of the Android Studio:
Android Studio 0.1.3 shows the folded text in XML layouts that it extracts from the string resources, but it fails to navigate back to the resource and doesn't offer to extract resources from the hardcoded strings inside XML. It appears to be a bug.
What seems to be missing from the above answers is that, in Android Studio, you must place the cursor in the string, click the mouse, and press Alt + Enter to bring up the Extract String Resource dialog
alt+Enter work when your setting string resource is on,
how to on string resource extractor
Goto Android studio 'Help' -> Find action -> type "extract string resource"
You will find a ON / OFF button. Switch on the option.

Leading Question Mark causes Eclipse "No resource found that matches the given name" Error

In my strings.xml file, I have:
<string name="menus_feedback">?Feedback</string>
and I get the eclipse error:
No resource found that matches the given name (at 'menus_feedback' with value '?Feedback').
If I remove the leading question mark:
<string name="menus_feedback">Feedback</string>
it's fine. Any clues as to why this occurs? Eclipse Helios Release 2.
n.b. Was going to use leading question mark just to indicate we need a translation for the string.
enclose the whole text in double quotes

renaming the name of the APP alone in Android Eclipse IDE

I created a wonderful app, but I want to rename the "application name" alone... (i.e the name seen by the user on the app icon ) .. ( this isn't package renaming)
How do I do it, without creating a new one ...
In the strings.xml file, there is an element app_name which is used in the AndroidManifest's application element as the app's name. Just change the value of app_name in the strings.xml file to change the name of your app.
You don't need to refactor to change the name that people see. That is set in your res->values->Strings.xml file. You can call it what you want.
you can try Refactor -> rename.

Categories

Resources