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 trial

Android Build a Blog Reader Android App Using Intents to Display and Share Posts Easy Sharing with Intents

Android 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!)



No. That idea of mine was rubbish! ;-) Didn't work.

Further, 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

Done 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


Ben Jakuben
Ben Jakuben
Treehouse Teacher

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

    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.blog_web_view, menu);
        return true;
Ben Jakuben
Ben Jakuben
Treehouse Teacher

Very 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" >



Exactly like that, yes.

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Okay, 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.

  1. Start by restarting Eclipse.
  2. Right-click on "res" and select Refresh. Just want to make sure it's totally in sync.
  3. Clean the project with Project > Clean, and then it will rebuild automatically.
  4. Open blog_web_view.xml and see if you can edit it again.

I'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.



Ben Jakuben
Ben Jakuben
Treehouse Teacher

Really 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:

  1. 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.

  2. 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').

  3. 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!

Brilliant - 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.