Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String.xml provides me wrong String for ProcessDialog

In my app I have translated everything. This includes my dialogs also. As of yesterday, everything worked perfectly. Today I've added a String, for a new dialog. When I run my app, it provides me wrong Strings which is very weird.

For example, I call String x and y and he shows me String w and z. Not only in my new dialog, also in my existing dialogs! As for lables, he puts everything right. Have I done something wrong?

In my String.xml file I've declarated many Strings, here's an example of one he mixes up.

<string name="EvenGeduld">Even geduld...</string>
<string name="TweetProgress">De Tweets worden ingeladen</string>
<string name="Voornaam">Voornaam</string>
<string name="Geboortedatum">Geboortedatum</string>

This is my code for my dialog (it's set in AsyncTask class, dialog is declarated on top of my class, initialized in onCreate()):

dialog.setTitle(R.string.EvenGeduld);
Resources res = getResources();
String test = (res.getString(R.string.TweetProgress));
dialog.setMessage(test);
dialog.show();
like image 434
Hannelore Avatar asked May 25 '11 07:05

Hannelore


2 Answers

try this.

activity.this.getResources().getString(R.String...etc);

and clean your project

Eclipse>>Project>>Clean
like image 88
Niranj Patel Avatar answered Nov 09 '22 01:11

Niranj Patel


Yes, cleaning your project will do the trick, but there is an exception.

If you have any errors in your strings.xml file, it will cause bunches of problems just like this. And you do not always get an error message (so much for xml!). For me the culprit is usually ' or " in long strings (like help messages) that do not have a backslash before them, like \' and \".

Since these error are not always caught be Eclipse, you must look very very carefully, fix these errors, AND THEN "clean" your project.

like image 24
SMBiggs Avatar answered Nov 09 '22 03:11

SMBiggs