Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSteve Hunter
57,712 PointsAndroid menu Action Bar
Hi All,
I'm adding the sharing icon to the action bar but have run into a couple of problems.
Firstly, within the 'menu' folder, I don't have a file called activity_blog_web_view.xml
; mine is just blog_web_view.xml
- no big deal.
However, there's nothing inside that at all. There's no file to delete. Again, no big deal.
The showstopper here is the inability to add anything. I click the 'Add' button and there's nothing to select - there's no Group or Item option. I get a modal window with the heading "Create a new element at the top level, in Temp" - but there's no options to select. (Why Temp??)
So I can't select anything to add; the OK button is greyed out.
Any thoughts? Is this because BlogWebViewActivity
extends Activity
rather than ActionBarActivity
? (I'll try that!)
Cheers,
Steve.
Steve Hunter
57,712 PointsFurther, where's there's the icons above the 'Add...' button (I & G) - I have none at all. I just have 'Az' above the button.
5 Answers
Steve Hunter
57,712 PointsDone that - and it still doesn't work. But chasing the errors around makes it look like I've done something wrong implementing this Activity.
Potentially, if we can understand why the .xml isn't called activity_blog_web_view.xml
then we'll understand what I did wrong.
This seems to be a resource issue of my creation!
As always, Ben Jakuben ; massive thanks for your direct help. #Legend
Steve.
Ben Jakuben
Treehouse TeacherThe naming difference sounds like a change in the tools themselves from when this video was first recorded. The Android tools have undergone a bunch of minor changes and one frustrating bigger one dealing with Fragments.
How does onCreateOptionsMenu()
look in your BlogWebViewActivity.java file? Is it using the right ID?
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.blog_web_view, menu);
return true;
}
Ben Jakuben
Treehouse TeacherVery strange! Sounds like a tools bug. I'll have to look into this. In the mean time, can you edit the XML directly? If so, here's what the XML view of the file should look like:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_share"
android:icon="@drawable/ic_action_share"
android:showAsAction="always"
android:title="@string/action_share">
</item>
</menu>
Steve Hunter
57,712 PointsExactly like that, yes.
Ben Jakuben
Treehouse TeacherOkay, let's try a clean and rebuild of your project after restarting Eclipse. If that doesn't work you can zip up your files and send them to help@teamtreehouse.com and I can look at them and help troubleshoot.
- Start by restarting Eclipse.
- Right-click on "res" and select Refresh. Just want to make sure it's totally in sync.
- Clean the project with Project > Clean, and then it will rebuild automatically.
- Open blog_web_view.xml and see if you can edit it again.
Steve Hunter
57,712 PointsI've done all that.
On the plus-side, I now have icons in the layout file and can add groups or items. That's progress!
However, every reference to R.
now generates an error in both classes. I've organised imports and the errors changed from the R.
itself to the parameter such as webView1
or activity_blog_web_view
. Those are named correctly but don't appear in the drop-down helper when creating or editing code. The error says:
Multiple markers at this line: webView1 cannot be resolved or is not a field R cannot be resolved to a variable
Console has the following errors which may be related:
[2014-05-30 09:32:16 - BlogReader] W/ResourceType(17370): ResXMLTree_node header size 0xc is too small. [2014-05-30 09:32:16 - BlogReader] /Users/OnlySteveH/Dropbox/Android Apps/BlogReader/res/menu/blog_web_view.xml:6: error: Error: No resource found that matches the given name (at 'title' with value '@string/action_share').
I'll figure out how to zip the files and send them over.
Thanks!
Steve.
Ben Jakuben
Treehouse TeacherReally sorry about my late reply, Steve Hunter! I got your files and imported them and then got distracted by something and forgot to return to them.
Anyhow, there was a silly problem hiding your real problem. Follow these steps and you'll see what I mean:
Delete libs/android-support-v4.jar. There is one in the appcompat_v7 project, and having 2 versions causes problems. I don't know why the 2nd one gets pulled in sometimes.
Clean your project, and then you will see this error:
BlogReader/res/menu/blog_web_view.xml:3: error: Error: No resource found that matches the given name (at 'title' with value '@string/action_share').
That means you need to add the following line to your strings.xml file:
<string name="action_share">Share</string>
Hope this gets you rolling again!
Steve Hunter
57,712 PointsBrilliant - thanks so much, Ben Jakuben - that works fine.
I now need to remember where I was up to and pick up from there!
Again, thanks for sparing the time to go over my project.
Steve.
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsNo. That idea of mine was rubbish! ;-) Didn't work.