Android not recognizing string resource - java

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?

Related

Vector drawables not loading in xml ResourceNotFoundException

I am having trouble with loading vector files in my splash background xml file. The vector has been loaded successfully because I can open the vector file in android studio and I get a small graphic of the vector on the side of the xml file. However, the design view of the xml file shows an error for the vector file, and I get a ResourceNotFoundException when trying to run my app.
Code below:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item android:drawable="#color/colorPrimary"/>
<item>
<bitmap
android:gravity="center"
android:src="#drawable/ic_loading_screen_logo"/>
</item>
</layer-list>
splash background.xml
My grade version is classpath 'com.android.tools.build:gradle:4.0.1'
and I have included the following line in my grade app file vectorDrawables.useSupportLibrary = true
It seems that any vector file that I use has this error, so there is some setting of some sort that is missing.
Please assist in anyway.
Thanks,
The problem is wrapping the xml drawable in a <bitmap/>
Try this:
Replace
<item>
<bitmap
android:gravity="center"
android:src="#drawable/ic_loading_screen_logo"/>
</item>
With:
<item android:gravity="center"
android:drawable="#drawable/ic_loading_screen_logo"/>
replace <bitmap to <item
make sure that your vector is in drawable folder not in drawable-24.
check vectory path may be its too long.

error: Multiple annotations found at this line:

I am implementing searchview in my app, for which I copied this options_menu.xml from a separate working project of searchview.
I get this error in res/menu/options_menu.xml
Multiple annotations found at this line:
- error: No resource identifier found for attribute 'actionViewClass' in package
'com.example.indianconstitution'
- error: No resource identifier found for attribute 'showAsAction' in package
'com.example.indianconstitution'
Code:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/action_search" // error in this line
android:icon="#drawable/ic_launcher"
android:title="#string/action_search"
yourapp:actionViewClass="android.support.v7.widget.SearchView"
yourapp:showAsAction="always" />
</menu>
Can anyone figure out this problem?
Thanks in advance...
Looks like you copied this from a project that uses appcompat-v7 into one that doesn't.
Either include appcompat-v7, following the instructions, or just replace yourapp:x attributes with android:x attributes. If you go this way, though, you should also replace the action view class with the corresponding one in the framework (i.e. android.widget.SearchView).

Error in Main.xml

I am getting the error: error: No resource identifier found for attribute 'showAsAction' in package:
I cannot find out why I am getting this error but I have been at it for hours without any sort of break through. I have searched google with many different resolutions but none that appear to work for me.
I would be grateful if someone could help direct me towards a fix to the error.
<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="org.nibbler.zoe.liteplayer.MainActivity" >
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:title="#string/action_settings"
app:showAsAction="never"/>
</menu>
Most likely showAsAction is not your attribute, hence not available in app: namespace. Did you mean android:showAsAction?
If u are having min ver below 14 and u want to add showAsAction for below 14 api devices, then u can use this.
1.)U need support library to be added in build path.
2.)Need to add app theme as Theme.appcompat.
3)Rest are as u are using means add ur own namespace with .../res-auto value and use that name with showAsAction
You can add support lib res like this http://developer.android.com/tools/support-library/setup.html
You need to extends ActionBarActivity instead of Activity.
For complete Action bar guide follow the link http://developer.android.com/training/basics/actionbar/setting-up.html

Having an error in my strings.xml file

<?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

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

Categories