Cannot Locate Strings that Exist - android

I have the following error:
From menu:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:appcompat="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/menu_item_new"
android:title="#string/menu_item_new"
appcompat:showAsAction="always"></item>
<item
android:id="#+id/menu_item_save"
android:title="#string/menu_item_save"
appcompat:showAsAction="always"></item>
<item
android:id="#+id/menu_item_delete"
android:title="#string/menu_item_delete"
appcompat:showAsAction="always"></item>
<item
android:id="#+id/menu_item_rate"
android:title="#string/menu_item_rate"></item>
<item
android:id="#+id/menu_item_website"
android:title="#string/menu_item_website"></item>
<item
android:id="#+id/menu_item_report"
android:title="#string/menu_item_report"></item>
</menu>
Even though all those strings do in fact exist:
<string name="menu_item_new">New</string>
<string name="menu_item_save">Save</string>
<string name="menu_item_delete">Cancel</string>
<string name="menu_item_rate">Rate on Google Play</string>
<string name="menu_item_website">Website</string>
<string name="menu_item_report">Report a Bug</string>
I have attempted to simply re-write the code as well as clean and rebuild, yet the error persists.
How can this be resolved?

resources tag is missing from strings.xml file.
Android couldn't locate the string resource.
Make following changes:
<resources>
<string name="menu_item_new">New</string>
<string name="menu_item_save">Save</string>
<string name="menu_item_delete">Cancel</string>
<string name="menu_item_rate">Rate on Google Play</string>
<string name="menu_item_website">Website</string>
<string name="menu_item_report">Report a Bug</string>
</resources>

Related

Android: Drawer items doesnt change title when language is changed

I implemented some string resources for english and romanian. Switching the locale works fine for text fields, but the titles for the drawer items doesnt change when language is changed.
I have the following configuration:
Setting the locale to "ro" in MainActivity
private fun setDefaultLocale(lang: String) {
val config = android.content.res.Configuration(resources.configuration)
val locale = Locale(lang)
Locale.setDefault(locale)
config.setLocale(locale)
config.setLayoutDirection(locale)
resources.updateConfiguration(config, resources.displayMetrics)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)
setDefaultLocale("ro")
.....
}
Menu resources:
<group android:checkableBehavior="single">
<item
android:icon="#drawable/ic_baseline_home_24"
android:id="#+id/home"
android:title="#string/menu_home" />
<item
android:icon="#drawable/ic_baseline_wallpaper_24"
android:id="#+id/news"
android:title="#string/menu_news" />
<item
android:icon="#drawable/ic_jungle"
android:id="#+id/jungleTimer"
android:title="#string/menu_timer" />
<item
android:icon="#drawable/ic_damage"
android:id="#+id/builds"
android:title="#string/menu_builds" />
<item
android:icon="#drawable/ic_baseline_settings_24"
android:id="#+id/settings"
android:title="#string/menu_settings" />
<item
android:icon="#drawable/ic_baseline_info_24"
android:id="#+id/about"
android:title="#string/menu_about" />
<item
android:icon="#drawable/ic_feedback"
android:id="#+id/feedback"
android:title="#string/menu_feedback" />
<item
android:icon="#drawable/ic_favorite"
android:id="#+id/rateapp"
android:title="#string/menu_rate" />
</group>
Default string xml file:
/* Menu translations */
<string name="menu_home">Home</string>
<string name="menu_news">News</string>
<string name="menu_timer">Jungle Timers</string>
<string name="menu_builds">Guides</string>
<string name="menu_settings">Settings</string>
<string name="menu_about">About</string>
<string name="menu_feedback">Feedback</string>
<string name="menu_rate">Rate the app</string>
Romanian strings xml file
/* Menu translations */
<string name="menu_home">Acasă</string>
<string name="menu_news">Noutăți</string>
<string name="menu_timer">Cronometru Junglă</string>
<string name="menu_builds">Ghid Campioni</string>
<string name="menu_settings">Setări</string>
<string name="menu_about">Despre</string>
<string name="menu_feedback">Feedback</string>
<string name="menu_rate">Dă-ne o notă</string>
Updating configuration will not restart your activity, so Drawer will not know that you changed locale on the device thus not changing the texts.
If you change your language in system settings it should work.
I propose recreating the activity after you change your configuration programmatically, for example with activity?.recreate() method

Emoji Compat Font Provider not found

I've setup EmojiCompat Following the documention I have the files
Import
implementation 'androidx.emoji:emoji:1.1.0'
font_certs.xml - Auto Generated
<?xml version="1.0" encoding="utf-8"?>
<resources>
<array name="com_google_android_gms_fonts_certs">
<item>#array/com_google_android_gms_fonts_certs_dev</item>
<item>#array/com_google_android_gms_fonts_certs_prod</item>
</array>
<string-array name="com_google_android_gms_fonts_certs_dev">
<item>
MIIEqDCCA5CgAwIBAgIJANWFuGx9.......
</item>
</string-array>
<string-array name="com_google_android_gms_fonts_certs_prod">
<item>
MIIEQzCCAyugAw....
</item>
</string-array>
</resources>
preloaded_fonts.xml - Auto Generated
<?xml version="1.0" encoding="utf-8"?>
<resources>
<array name="preloaded_fonts" translatable="false">
<item>#font/montserrat_bold_downloadable</item>
</array>
</resources>
montserrat_bold_downloadable - Auto Generated
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:app="http://schemas.android.com/apk/res-auto"
app:fontProviderAuthority="com.google.android.gms.fonts"
app:fontProviderPackage="com.google.android.gms"
app:fontProviderQuery="name=Montserrat&weight=700"
app:fontProviderCerts="#array/com_google_android_gms_fonts_certs">
</font-family>
And now when calling to initialise this it's failing, but the callback returns null so I dug through to see where it was failing.
EmojiCompat.init(
FontRequestEmojiCompatConfig(
this,
FontRequest(
"com.google.android.gms.fonts",
"com.google.android.gms",
"name=Montserrat",
R.array.com_google_android_gms_fonts_certs
)
).setReplaceAll(true)
)
The error that it's throwing internally is;
android.content.pm.PackageManager$NameNotFoundException: No package found for authority: com.google.android.gms.fonts
I can't find anything to do with this issue anywhere.

What does "add-resource" in Android resource xml file do?

I found that there are following statement in package/apps/UnifiedEmail package in android source code:
<add-resource name="RecipientEditTextViewStyle" type="style" />
What does this "add-resource" element mean?
The source code: https://github.com/CyanogenMod/android_packages_apps_UnifiedEmail/blob/cm-11.0/res/values/attrs.xml
<resources>
<string name="app1_name">MyAppName</string>
</resources>
is the same thing as
<resources>
<add-resource type="string" name="app1_name">MyAppName</add-resource>
</resources>
so
<add-resource name="RecipientEditTextViewStyle" type="style" />
is the same thing as
<style name = "RecipientEditTextViewStyle"/>

error: ``Syntax error on token "heading", delete this token'' in eclipse

So I am following a tutorial on how to make a TicTacToeGame.
I got an error the same as this: No resource found that matches the given name (at 'title' with value '#string/action_settings')
so I added this line in my code:
<string name="action_settings">Settings</string>
Now I got this new error: ``Syntax error on token "heading", delete this token''.
error is in the class: R.java > R > string.
this line:
public static final class string {
public static final int =0x7f0a0028; \\red mark # int
I think the error is because I ``settings'' isnt the word I should use, but im not quit sure.
this is my main.xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.tictactoetest.MainActivity" >
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:title="#string/action_settings"
app:showAsAction="never"/>
</menu>
this is my strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">testjk</string>
<string name="hello_world">Hello world!</string>
<string name="turn_human">Your turn.</string><string name="first_human">You go first.</string>
<string name="turn_computer">Android\'s turn</string>
<string name="result_tie">It\'s a tie!</string>
<string name="result_human_wins">You won!</string>
<string name="result_android_wins">You lose!</string>
<string name="one">1</string>
<string name="two">2</string>
<string name="three">3</string>
<string name="four">4</string>
<string name="five">5</string>
<string name="six">6</string>
<string name="seven">7</string>
<string name="eight">8</string>
<string name="nine">9</string>
<string name="info">Info</string>
<string name="human">Human: </string>
<string name="ties">Ties: </string>
<string name="android">Android: </string>
<string name="contact_heading">Contact Info</string>
<string name="action_settings">Settings</string>
<string name="contact_info">
<b>Name:</b> hiii
<b>Achternaam</b> hello
<b>Email</b> test#haha.com
</string>
<string name="about heading"> About </string>
<string name="">This app allowed you to play a game tic tac toe
blablalbalbalblalbalblalbalblablalblablalblalbla</string>
</resources>
public static final int =0x7f0a0028; \\red mark # int
There's no name here
EG:
public static final int ticTacBlahBlah = 0x7f0a0028;
because of
<string name="">This app allowed you to play a game tic tac toe
blablalbalbalblalbalblalbalblablalblablalblalbla</string>
Put a name in, and things should work.
<string name="ticTacBlahBlah">This app allowed you to play a game tic tac toe
blablalbalbalblalbalblalbalblablalblablalblalbla</string>

Android: XML resources (values)

I must make a few translations for my app.
But when I compile my app, console write:
[2012-11-24 15:31:43 - com.ddm.ctimer.MainForm] W/ResourceType( 4892): Bad XML block: header size 297 or total size 0 is larger than data size 0
[2012-11-24 15:31:43 - com.ddm.ctimer.MainForm] C:\Users\Roman\Desktop\NewTimer\NewTimer\res\values-fr\strings.xml:6: error: Found text "
[2012-11-24 15:31:43 - com.ddm.ctimer.MainForm] В В В В  " where item tag is expected
Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">CTimer</string>
<!--RUS strings-->
<!--MainForm-->
<string name="main_form_sec">Chronomètre</string>
     <string name="main_form_tim"> Minuterie </string>
     <string name="main_form_set"> Paramètres </string>
<string name="main_form_bg">#000000</string>
<!--Menu-->
<string name="menu_about">À propos du programme</string>
<string name="menu_buy">Supprimer les annonces</string>
<!--Preferences(Settings)-->
Most probably you have a problem with the encoding, resource files are supposed to be encoded in UTF-8.
Please, try to replace "Chronomètre" with something in plain English and see if your error disappears or moves to the next "translated" line.
It's better to use colors.xml for colors:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="main_form_bg">#000000</color>
</resources>

Categories

Resources