“Hardcoded string xxx should use @string resource” issue


“Hardcoded string xxx should use @string resource” issue



I'm getting the following error in hello world activity code:


Description Resource Path Location Type
[I18N] Hardcoded string "and this is a clickable button!",
should use @string resource
activity_hello_world.xml/HelloWorld/res/layout line 21 Android Lint Problem



Please help me out.





This is just an warning , trying to bring your code to industry standard . Copy your hard coded string and paste it in file called String.xml .
– Code_Life
Nov 3 '12 at 9:57





2 Answers
2



This is not an error, this is a Lint warning. So you can run the App, but the recommended way to display texts(on TextViews, Buttons etc.) is to use string references. You have to go to your res folder and there will be a strings.xml file under values. Add this in there:


<string name="my_string">Your Text!</string>



And to set text on you button you then have to do this:


android:text="@string/my_string"





but i am not able to run the app still
– user1795999
Nov 3 '12 at 10:06





Are you getting any other errors?
– Ahmad
Nov 3 '12 at 10:06





.java file shows 9 errors
– user1795999
Nov 3 '12 at 10:07





no others eroors in the xml file
– user1795999
Nov 3 '12 at 10:08





What do the errors say?
– Ahmad
Nov 3 '12 at 10:08



example- (of keypad)



put this under file string.xml under values folder


<string name="keypad_title">Keypad</string>



put this code under keypad.xml under layout folder


<Button android:id="@+id/keypad_1"
android:text="1">
</Button>




Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).


Would you like to answer one of these unanswered questions instead?

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Export result set on Dbeaver to CSV

Opening a url is failing in Swift