• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps String?

Hi I've got this very annoying problem which is preventing me from going further.

The strings.xml file in the values folder in Res.
I cannot seem to get the java file to recognise the resources. The java file doesn't seem to recognise the strings in res. I have imported android.R but to no avail.
This is a snippet from the java file"

menu.findItem(R.id.menu_toggle_clock).setTitle(
getClockVisibility() ? R.string.hide_clock
: R.string.show_clock);
"



and this is from the strings section



<string name="show_clock">Show clock</string>



I keep getting an error that it" cannot be resolved or is not a field"

This seems to apply to every string I have in the values folder. I have double checked the values folder and there's no errors.



your advice would be greatly appreciated!

Thanks.
 
By the way...this may be because there is nothing in the gen file, especially the R.java file. I can't seem to open/view the gen file? It's not clickable? What can I do to generate the R.java file?
 
Hi finally managed to get the gen file working by restarting the project. However the problem remains the same.

I keep getting an error saying that "error: found text" and it's an android AAPT problem. I guess that's why r.java ain't taking the string file?
 
When in doubt, Project > Clean

Anyways, the builder pattern is an anti pattern IMHO

So maybe try something like this:
Code:
// not sure what you're setting the text of 
// so the 1st line here is a guess
TextView myTextView = (TextView) menu.findItem(R.id.menu_toggle_clock);
boolean isVisible = getClockVisibility() 
String hideString = getString( R.string.hide_clock );
String showString = getString( R.string.show_clock );
String myString = isVisible ? hideString : showString ;
myTextView.setTitle( myString );
IMHO The problem with the builder pattern is that it's really to hard read and doesn't give as useful errors.

While the way I have it is more typing, breaking it down into little baby steps like that makes it easy to see exactly what each step does at a glance, and hence easy to refactor and debug.

Also, it might help if you could explain where you're calling the code from. Are you in an inner class? Anonymous inner type? The fact that you are calling menu.findItem(id) leads me to suspect you may have some scope issue.


HTH
 
Hi thanks for your reply. Everytime I clean the project, the r.java file disappears and I am unable to get it back. i've had to do the project 10 times as a result of this.

The main issue is that the strings, values, layouts aren't showing up in the r.java file. But the drawables and such are in the r.java file. r.Java does have "

public static final class string {
public static final int app_name=0x7f050001;
public static final int hello=0x7f050000;"


But it's supposed to show these:


<?xml version="1.0" encoding="utf-8" ?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">

- <!-- Label shown on launcher icon
-->
<string name="app_label">Alarm Clock</string>
- <!-- Menu item on Alarm Clock screen: Add alarm
-->
<string name="add_alarm">Add alarm</string>
- <!-- Context Menu Item on Alarm Settings screen: Delete alarm
-->
<string name="delete_alarm">Delete alarm</string>
- <!-- Context Menu Item on Alarm Settings screen: Enable alarm
-->
<string name="enable_alarm">Enable alarm</string>
- <!-- Context Menu Item on Alarm Settings screen: Disable alarm
-->
<string name="disable_alarm">Disable alarm</string>
- <!-- Delete alarm confirmation dialog message.
-->
<string name="delete_alarm_confirm">This alarm will be deleted.</string>
- <!-- Menu item on Alarm Clock screen: Show clock
-->
<string name="show_clock">Show clock</string>
- <!-- Menu item on Alarm Clock screen: Hide clock
-->
<string name="hide_clock">Hide clock</string>
- <!-- Setting label on Set alarm screen: Label
-->
<string name="label">Label</string>
- <!-- Default label to display for an alarm
-->
<string name="default_label">Alarm</string>
- <!-- Preference category on Alarm Settings screen: Set alarm
-->
<string name="set_alarm">Set alarm</string>
- <!-- Setting labels on Set alarm screen: Vibration on or off
-->
<string name="alarm_vibrate">Vibrate</string>
- <!-- Setting labels on Set alarm screen: Repeat
-->
<string name="alarm_repeat">Repeat</string>
- <!-- Setting labels on Set alarm screen: Select alarm ringtone
-->
<string name="alert">Ringtone</string>
- <!-- Setting labels on Set alarm screen: Set time
-->
<string name="time">Time</string>
- <!-- Button labels on the alarm dialog: Dismiss
-->
<string name="alarm_alert_dismiss_text">Dismiss</string>
- <!--
Alarm Alert screen: this message is shown after an alarm rung
unattended for a number of minutes. It tells the user that
the alarm has been silenced.

-->
- <string name="alarm_alert_alert_silenced">
Alarm silenced after
<xliff:g id="minutes">%d</xliff:g>
minutes
</string>
- <!-- Button labels on the alarm dialog: Snooze
-->
<string name="alarm_alert_snooze_text">Snooze</string>
- <!--
Toast that appears after Alarm is snoozed from the Alarm
dialog. Says the alarm will snooze for xxx minutes.

-->
- <string name="alarm_alert_snooze_set">
Snoozing for
<xliff:g id="minutes">%d</xliff:g>
minutes.
</string>
- <!--
0: nothing
1: days
2: hours
3: days hours
4: minutes
5: days minutes
6: hours minutes
7: days hours minutes


-->
<skip />
- <!--
Alarm confirmation toast: Describes how long from now until
alarm fires

-->
- <string-array name="alarm_set">
<item>This alarm is set for less than 1 minute from now.</item>
- <item>
This alarm is set for
<xliff:g id="DAYS" example="2 days">%1$s</xliff:g>
from now.
</item>
- <item>
This alarm is set for
<xliff:g id="HOURS" example="2 hours">%2$s</xliff:g>
from now.
</item>
- <item>
This alarm is set for
<xliff:g id="DAYS" example="2 days">%1$s</xliff:g>
and
<xliff:g id="HOURS" example="2 hours">%2$s</xliff:g>
from now.
</item>
- <item>
This alarm is set for
<xliff:g id="MINUTES" example="2 minutes">%3$s</xliff:g>
from now.
</item>
- <item>
This alarm is set for
<xliff:g id="DAYS" example="2 days">%1$s</xliff:g>
and
<xliff:g id="MINUTES" example="2 minutes">%3$s</xliff:g>
from now.
</item>
- <item>
This alarm is set for
<xliff:g id="HOURS" example="2 hours">%2$s</xliff:g>
and
<xliff:g id="MINUTES" example="2 minutes">%3$s</xliff:g>
from now.
</item>
- <item>
This alarm is set for
<xliff:g id="DAYS" example="2 days">%1$s</xliff:g>
,
<xliff:g id="HOURS" example="2 hours">%2$s</xliff:g>
, and
<xliff:g id="MINUTES" example="2 minutes">%3$s</xliff:g>
from now.
</item>
</string-array>
- <!-- Alarm confirmation toast: singular day
-->
<string name="day">"1 day"</string>
- <!-- Alarm confirmation toast: plural days
-->
- <string name="days">
"
<xliff:g id="days">%s</xliff:g>
days"
</string>
- <!-- Alarm confirmation toast: singular hour
-->
<string name="hour">1 hour</string>
- <!-- Alarm confirmation toast: plural hours
-->
- <string name="hours">
<xliff:g id="hours">%s</xliff:g>
hours
</string>
- <!-- Alarm confirmation toast: singular minute
-->
<string name="minute">"1 minute"</string>
- <!-- Alarm confirmation toast: plural minutes
-->
- <string name="minutes">
"
<xliff:g id="minutes">%s</xliff:g>
minutes"
</string>
- <!--
Repeat options that appear under an alarm on main Alarm Clock
screen to identify repetition schedule: special case for when
the alarm is set to repeat every day

-->
<string name="every_day">every day</string>
- <!--
Repeat options that appear under an alarm on main Alarm Clock
screen to identify repetition schedule: special case for when
the alarm is set to never repeat

-->
<string name="never">Never</string>
- <!--
Repeat options that appear under an alarm on main Alarm Clock
screen to identify repetition schedule: concatenate days with
this character, i.e. "Mon, Tue, Wed"

-->
<string name="day_concat">", "</string>
- <!--
Appears at the top of the Clock Picker screen: Tell user to
select a clock to display

-->
<string name="clock_instructions">Select a clock to display.</string>
- <!-- Label for analog clock gadget, shown in list of all gadgets
-->
<string name="analog_gadget">Analog clock</string>
- <!-- Menu item title for general Alarm Clock Settings
-->
<string name="settings">Settings</string>
- <!--
Setting title for whether the alarm should play in silent mode.
Usually, silent mode only affects the ringer, but this setting
will make the alarms respect silent mode too.

-->
<string name="alarm_in_silent_mode_title">Alarm in silent mode</string>
- <!-- Setting summary for whether the alarm should play in silent mode.
-->
<string name="alarm_in_silent_mode_summary">Play alarm even when the phone is in silent mode</string>
- <!-- Setting title for changing the snooze duration.
-->
<string name="snooze_duration_title">Snooze duration</string>
- <!--
Entries listed in the ListPreference when invoking the snooze duration
preference.

-->
- <string-array name="snooze_duration_entries">
<item>5 minutes</item>
<item>10 minutes</item>
<item>15 minutes</item>
<item>20 minutes</item>
<item>25 minutes</item>
<item>30 minutes</item>
</string-array>
- <!--
Values that are retrieved from the ListPreference. These must match
the snooze_duration_entries above.

-->
- <string-array name="snooze_duration_values">
<item>5</item>
<item>10</item>
<item>15</item>
<item>20</item>
<item>25</item>
<item>30</item>
</string-array>
- <!-- Done button when editing an alarm.
-->
<string name="done">Done</string>
- <!-- Revert button when editing an alarm.
-->
<string name="revert">Revert</string>
- <!-- Setting title for changing the alarm volume.
-->
<string name="alarm_volume_title">Alarm volume</string>
- <!-- Setting summary for changing the alarm volume.
-->
<string name="alarm_volume_summary">Set the volume of alarms</string>
- <!-- Summary for the alarm preference when silent is chosen.
-->
<string name="silent_alarm_summary">Silent</string>
- <!-- Text to display in the small text of the notification
-->
<string name="alarm_notify_text">Select to snooze or dismiss this alarm.</string>
- <!-- Text to display in the notification ticker and label
-->
- <string name="alarm_notify_snooze_label">
<xliff:g id="label">%s</xliff:g>
(snoozed)
</string>
- <!-- Text to display in the notification when the alarm has been snoozed
-->
- <string name="alarm_notify_snooze_text">
Alarm set for
<xliff:g id="time">%s</xliff:g>
. Select to cancel.
</string>
- <!-- Title of the setting to change the volume/camera button behavior.
-->
<string name="volume_button_setting_title">Side button behavior</string>
- <!-- The summary of the side button setting.
-->
<string name="volume_button_setting_summary">Set the desired behavior of the side buttons when pressed during an alarm</string>
- <!-- Entries listed in the setting for the side-button action.
-->
- <string-array name="volume_button_setting_entries">
<item>None</item>
<item>Snooze</item>
<item>Dismiss</item>
</string-array>
- <!-- Values for the side-button setting.
-->
- <string-array name="volume_button_setting_values">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
</resources>
 
if the file named correctly?

is it:

/res/values/strings.xml

because:

public static final int app_name=0x7f050001;
public static final int hello=0x7f050000;"

those look like they are from the new project wizard
 
Back
Top Bottom