I basically copy & pasted the code from right above and replaced the necessary tidbits, yet I still get this error. I'm trying to make a "Refresh" item in my menu.
XML code:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="#string/action_settings"/>
<item
android:id="#+id/refresh_tasks"
android:title="#string/refresh"/>
</menu>
HomeActivity.java code:
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.refresh_tasks: //line where I get error
loadTasksFromAPI(TASKS_URL);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
I've searched across the internet, but I haven't managed to fix this. I assume something is wrong with my XML, but I don't see what it could be.
So, apparently my R.java stopped updating for some reason. My code was correct, but it wouldn't update. Editing the AndroidManifest.xml file and then saving seems to force R.java into updating. It's as simple as adding a space and then deleting the space from your AndroidManifest.xml file before you save (though, you could leave the space if you wish... It shouldn't cause an error).
Make sure there are no errors in any of your resources
. This would cause AAPT to stop generating a new R.class for you
Clean and rebuild the project
EDIT: Try to add this at the beginning of the xml:
<?xml version="1.0" encoding="utf-8"?>
Related
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/action_shuffle"
android:icon="#drawable/rand"
android:orderInCategory="1"
android:showAction="always"
android:title="shuffle"/>
<item
android:id="#+id/action_end"
android:icon="#drawable/end"
android:orderInCategory="2"
android:showAction="always"
android:title="End"/>
</menu>
#Override
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()){
case R.id.action_shuffle:
//shuffle
break;
case R.id.action_end:
stopService(playIntent);
musicSrv=null;
System.exit(0);
break;
}
return super.onOptionsItemSelected(item);
}
I am having sleepless night on this matter. I have tried all I could but this is giving me real time headache.
At first it was uri not registered error but after I validated the error now read thus:
Error:External resource http://schemas.android.com/apk/res/android is not registered.
How do I register this?
Error #2
Error:(2, 66) cvc-elt.1.a:cannot find the declaration of element of 'menu'
Error: Premature end of file
Menu must be in menu resource folder.
Check the steps below this code.
remove the below line from menu file, its not required :
<?xml version="1.0" encoding="utf-8"?>
see i have edited your menu file code below :
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/action_shuffle"
android:icon="#drawable/rand"
android:orderInCategory="1"
app:showAction="always"
android:title="shuffle"/>
<item
android:id="#+id/action_end"
android:icon="#drawable/end"
android:orderInCategory="2"
app:showAction="always"
android:title="End"/>
</menu>
Edit :
After seeing your code, i found mistake you have done. You created menu file in wrong folder. you need create menu file in res directory. I am giving you steps for creating menu file.
Note : delete your menu file or save in your computer before going this steps. remember menu file name should not be menu, because same name file or folder you cant create in android studio
Steps:
Right click on res directory
click on new
click on Android Resource directory
select menu in Resource type
click on ok
now copy paste your menu file in menu directory or you can go to next steps for creating new menu file like below :
Steps for creating menu file :
Right click on menu directory
click on new
select menu resource file
enter the name of menu file you want to create eg. "dashboard_menu"
now add your code you want to add in menu file
I'm trying direct each popup menu item to the another activity by using intent,but i get an error shown below:
This is my java code of popup menu:
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.one:
Intent i = new Intent(Cihazlar.this,MainActivity.class);
startActivity(i);
return true;
case R.id.two:
Intent i2 = new Intent(Cihazlar.this,Kampanya.class);
startActivity(i2);
return true;
}
return true;
}
});
And this is popup menu xml:
<menu xmlns:androclass="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/tools">
<item
android:id="#+id/one"
androclass:title="Senin Dünyan" />
<item
android:id="#+id/two"
androclass:title="Destek" />
<item
android:id="#+id/three"
androclass:title="Sıkça Sorulan Sorular" />
So why am i getting this error? Any help will be appreciated.
the problem is not at run time. It's compile time error. So if error is like resource not found then error is while importing R package or error in menu.xml.
But menu.xml looks proper, so I think, main problem is with R.java import. Check you have not imported com.android.R. It should be your <package_name>.R.
And even if this is ok, then your resources are not compiled completely. There might be some error at some other resource file (.xml file)
The very last thing one can try is to rebuild your app and then check out
EDIT
I think error is in menu.xml file itself. Try below code, unless you have made some customize stuff-
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/one"
android:title="Senin Dünyan" />
<item
android:id="#+id/two"
androclass:title="Destek" />
<item
android:id="#+id/three"
android:title="Sıkça Sorulan Sorular" />
bro have u declared it in Manifest plz post your manifest code
I am trying to implement the SearchView ActionBar item as android developers says but I am having some trouble.
(http://developer.android.com/guide/topics/ui/actionbar.html).
There are two mistakes that although I have looked for a lot, I have not been able to find the solution.
1) I have a problem with the class MenuItemCompat. It says:
The method getActionView(MenuItem) is undefined for the type MenuItemCompat
I can only use for this class the following methods:
setShowAsAction(item, actionEnum)
setActionView(item, view)
Here it is the code
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.restloader, menu);
MenuItem searchItem = menu.findItem(R.id.search_menu);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
// Configure the search info and add any event listeners
return super.onCreateOptionsMenu(menu);
}
2) There is a problem with this:
xmlns:myapp="http://schemas.android.com/apk/res-auto"
I don't understand why it is used but if google says it, it must be appropriate.
Error message:
Multiple annotations found at this line:
- error: No resource identifier found for attribute 'actionViewClass' in package
'com.example.pruebahttp3'
- error: No resource identifier found for attribute 'showAsAction' in package
'com.example.pruebahttp3'
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res-auto" >
<item
android:id="#+id/search_menu"
android:orderInCategory="100"
android:title="#string/search"
android:icon="#drawable/ic_search_category_default"
myapp:showAsAction="ifRoom|collapseActionView"
myapp:actionViewClass="android.support.v7.widget.SearchView">
</item>
Thank you very much!
i have got the same problem, i solved it by using the follow code. Be care of your namespace.`
<!-- Search, should appear as action button -->
<item
android:id="#+id/action_search"
android:icon="#drawable/abc_ic_search"
share:showAsAction="ifRoom"
share:actionViewClass="android.support.v7.widget.SearchView"
android:title="#string/abc_searchview_description_search" />
`
For the 1st:Fixing the second one will fix this :)
For the 2nd:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res-auto" >
Change myapp to you application namespace com.xxx.xxx
Try to copy the lib files directly from yourFolder\sdk\extras\android\support\v7\appcompat\libs
I have a similar problem,but It occurs to me when i directly copy the JAR library file rather than following the android support library procedure. Try the opposite it might work for you.
Kinda weird if you ask me.
I want to have an Menu item in the ActionBar that visualizes a boolean value. If this boolean value is true, the icon should start animating a series of 2 images in a loop. I did the following:
I added an item in the menu.xml file:
<item
android:id='#+id/myAnimation'
android:icon='#drawable/pic1'
android:showAsAction='ifRoom'>
</item>
I created an animation-list:
<?xml version='1.0' encoding='utf-8'?>
<animation-list xmlns:android='http://schemas.android.com/apk/res/android'
android:oneshot='false' >
<item
android:drawable='drawable/pic1'
android:duration='100' />
<item
android:drawable='drawable/pic2'
android:duration='100' />
</animation-list>
In the method onCreateOptionsMenu I assign this menu item to a variable
myMenuItem = menu.findItem(R.id.myAnimation);
Now, I was hoping to add an animation which would get executed whenever I tell the menu item to animate. But I wasn't able to come even close.
is this even possible?
How can I do that?
Thanks! Any help is appreciated!
Edit:
The App should support API from 8
I did ((AnimationDrawable) item.getIcon()).start(); in onCreateOptionsMenu(Menu menu)
This did not work. Then I thought, maybe it should be done on the UI thread, and then this worked:
someView.postDelayed(new Runnable() {
#Override
public void run() {
((AnimationDrawable) item.getIcon()).start();
}
}, 1000);
I was looking for the same thing and just found your question unanswered, so here is the solution, from the Android dev website:
((AnimationDrawable)myMenuItem).start();
The res folder inside of bin is supposed to contain .dex,.apk and .ap_ i think.Mines gone empty somehow causing errors like not being able to access the layout resources.I have tried clean and build but it doesent seem to work.Just seem to create an empty res folder.So any idea how to fix this?
Thanks.
Ok my problem is with an xml file i'm creating inside of res/menu inorder to create an options menu:
options.xml:
<?xml version="1.0" encoding="UTF-8"?>
<menu>
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/setmenu"
android:title="#string/settings"
android:icon="#android:drawable/ic_menu_preferences"></item>
<item
android:id="#+id/helpmenu"
android:title="#string/help"
androidLicon="#android:drawable/ic_menu_help"></item>
</menu>
Heres the error i am getting:
Description Resource Path Location Type
Unparsed aapt error(s)! Check the console for output. TriviaQuiz line 1 Android ADT Problem
Console Messages:
[2011-11-19 16:47:24 - TriviaQuiz] W/ResourceType( 4672): Bad XML block: header size 116 or total size 7602372 is larger than data size 0
[2011-11-19 16:47:24 - TriviaQuiz] H:\workspace\TriviaQuiz\res\menu\options.xml:5: error: Error parsing XML: unbound prefix
Any idea what it is.
I find that an error in one of my resources (usually a layout) causes this. Missing quotes or /> in particular are a good starting point - that's my personal blind spot and eclipse punishes it mercilessly!
As alextsc says, check everything you edited recently.