Having an error in my strings.xml file - java

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">DataGush Alpha</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string-array name="menu_items">
<item >Top Lists</item>
<item >Map</item>
<item >Search</item>
</string-array>
</resources>
I am getting these errors:
[2014-03-02 15:31:32 - DataGushAlpha] W/ResourceType(64288): ResXMLTree_node header size 0 is too small.
[2014-03-02 15:31:32 - DataGushAlpha] C:\Users\anshv_000\workspace\DataGushAlpha\res\values\strings.xml:12: error: Error parsing XML: mismatched tag
[2014-03-02 15:31:32 - DataGushAlpha] C:\Users\anshv_000\workspace\DataGushAlpha\res\menu\main.xml:3: error: Error: No resource found that matches the given name (at 'title' with value '#string/action_settings').

Try to check the XML file in a simple text editor for errors.
Sometimes when you let Eclipse/ADT autocomplete inline it just leaves some garbage there that is not visible in the editor somehow. It happens frequently to me.

I have had some problems with incorrect new line characters sometimes, please check the file and ensure that the xml is correct.
You should see whats wrong in the string.xml file in eclipse, shows up as a error in the editor or you could look in the problems view. If the error is not shown in the string.xml file then it's not a problem with the file, in this case the R file hasn't been updated correctly and therefore the string resource cannot be found, this happens for me from time to time. The solution to this is usually to clean and build the project, alternatively close and open the project.

Try to delete the space between item and >
<item>Top Lists</item>
<item>Map</item>
<item>Search</item>
and check this tag 'action_settings': there is no String with this tag

Related

Edit strings.xml file content in Android

I want to allow the users to enter in text using the settings template in android studio.
And display this in a textview.(which is already set)
settings_activity_settings.xml
is
<resources>
<string name="title_activity_settings">Settings</string>
<!-- General settings -->
<string name="pref_header_general">General</string>
<string name="pref_title_display_name">Enter Team 1</string>
<string name="pref_title_display_name_2">Enter Team 2</string>
</resources>
how to i retrieve this data
First of all your approach is not correct.
Because, you can't change resource files during runtime. Strings are hard-coded in the string.xml file and hence can't be changed during runtime.
I suggest you read this, it will help you understand why android framework don't want you to edit the file in runtime.
Now, the solution to your problem? Simple, save the string you get from user in to Shared Preference and load it int text views from there.

Android not recognizing string resource

In my android app, I have a string
<string name="action_upload">Upload Image</string>
in the strings file. Then in a menu file I have
navigation_screen.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="android.arin.NavigationScreen" >
<item
android:id="#+id/action_upload"
android:orderInCategory="100"
android:showAsAction="never"
android:title="#string/action_upload"/>
<item
android:id="#+id/action_forward"
android:icon="#drawable/ic_action_forward"
android:title="#string/action_forward"
android:showAsAction="ifRoom" />
</menu>
However when I try to run it, I get an error saying:
[2014-06-19 17:26:18 - ARIN] W/ResourceType( 9060): ResXMLTree_node size 0 is smaller than header size 0x100.
[2014-06-19 17:20:26 - ARIN] C:\Users\NAME\Documents\NAME\NAME\ARIN\res\menu\navigation_screen.xml:5: error: Error: No resource found that matches the given name (at 'title' with value '#string/action_upload').
I even tried a Project clean in eclipse, but still problem persists.
Does anyone know how to fix it?
Thanks
This may seem like a weird answer, but did you save the xml file. Hit Ctrl-S and try it again.
If that doesn't work: Are the other strings you declared in the strings.xml file visible?

Android [string array] cannot be resolved or is not a field

I'm getting an error about a string array (located in strings.xml) not being able to be resolved.
I've done everything the internet says:
Restarted Eclipse
Deleted my R.java file inside the gen folder
My values folder is still inside the res folder, not moved
None of my XML files have erros
Ran Project -> Clean
I don't have android.R imported in my class.
Checked the R.java class, it indeed doesn't have an app_categories property (my array's name)
The relevant part of the XML:
<string-array name="app_categories">
<item >Cat 1</item>
<item >Cat 2</item>
<item >Cat 3</item>
<item >Cat 4</item>
<item >Cat 5</item>
<item >Cat 6</item>
<item >Cat 7</item>
<item >Cat 8</item>
<item >Cat 9</item>
</string-array>
The Java code:
String[] categoryNames = getResources().getStringArray(R.string.app_categories);
All my other strings are visible. I have another array defined just like this one, and that one isn't visible either.
Exact error below:
app_categories cannot be resolved or is not a field [class_name].java [path] line 45 Java Problem
Just try out this way :
getResources().getString(R.array.app_categories_list);
Instead of R.string use R.array you will get your arraylist.
Don't put your string arrays in strings.xml You must create a new file called arrays.xml and place them there.
And when calling you need R.arrays.myarray, not R.strings.MyArray
After cleaning your project try restarting the adb server by running adb kill-server and adb start-server from the command line
a solution may be to create the R manually:
just hover over the error in the activity file where the problem was and then manually create it, which will cause R to generate the string array you created in strings.xml

How to make android app with option for Tamil and English?

In android app, within that app has settings option such as English and Tamil
If user select Tamil, with in the app only display in Tamil, in all activities all labels should in Tamil. if the user select English all labels are changed to English. How to make that?
Please give any idea....
Follow this Link: Android : translate the language of whole app on click
Then Do like this, Add the string values for each locale into the appropriate file.
English (default locale), /values/strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="title">My Application</string>
<string name="hello_world">GoodMorning</string>
</resources>
Tamil, /values-tl/strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="title">My Application</string>
<string name="hello_world">Kaalai vanakkam</string>
</resources>
Link: http://developer.android.com/training/basics/supporting-devices/languages.html
Have a look at this question.
Basically you have to put the translated Strings in a folder in the res folder.

Difference between android:text="#string/hello" and normal right click--> Text view component--> EditText

While I am working with help of tutorial I found this in textview android:text-"#string/hello" it shows some error.
Then I went through graphical view and right click the component and enter the text. Then that error removes and notifies me that
**Hardcoded string hello should use String resources**
In android, "#string/" refer to the string.xml in Project>res>values> location in your package explorer.
String.xml contains a xml file which refer to a string with an id.
Eg:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World</string>
<string name="app_name">My app</string>
</resources>
Here name="hello" is the id & "Hello World" is its value. When #string/hello is used, the value will be shown.
Similar is the case with "#drawable/". It will refer to the images used. and many more.
You can set text in text view programmatically. Eg:
TextView tv = (TextView)findViewById(R.id.text1); //text1 is the id u provide in xml file
tv.setText("Hello World");
I hope it helped you.
#string/hello simply notice Android to load the String in a XML file located into the /values directory (strings.xml).
hello is the ID of the String specified by name="hello" into that XML.
Android Studio is very unstable. Previously, it auto generated the corresponding statement in the string.xml . Tutorials using previous versions get beginners stuck because of that.
How string.xml works
Android Studio expects you to write all texts in one place, in the string.xml file. In all other files, you just put abbreviations. e.g.
android:text="#string/Hello_world"
means that find the abbreviation Hello_world in the string.xml file and replace it by the intended text.
In string.xml, the corresponding statement which should be written is:
<string name="Hello_world">Hello world!</string>
and that should do the job!
It is possible to just write android:text="Hello world!" (This is what hardcoding is). If you intend to be an android dev, then you would not maximize efficiency.
Why? string.xml
Having all texts in one file eases many things. Like translation if needed and easy change. However, you should choose meaningful abbreviations!

Categories