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

Help on Eclipse

Hi! I'm currently learning the Blog Reader App unit. I am mimicking Ben Jakuben's instructions, just to get a feel about how it works. My only problem is that I can't launch the emulator because I have errors that I don't really know how to fix. I find it strange though, considering that I pretty much copied Ben's example.

package com.teamtreehouse.blogreader;

import android.R; import android.app.ListActivity; import android.os.Bundle; import android.view.Menu;

public class MainListActivity extends ListActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_list);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main_list, menu);
    return true;
}

}

It says that the "activity_main_list" is an error (in both the setContentView and getMenuInflater). I'm a bit new to Android, so I'm kind of a noob (meaning that sometimes I don't notice something). Help would be greatly appreciated!

What error is it reporting if you hover over it? Make sure that your layout files are named appropriately. I know that in my project the menu is just named main_list.xml. You can type R.layout. and then pause to get a list of resources that you can use.

It says that "activity_main_list cannot be resolved or is not a field". It shouldn't say that though, because mine is named "activity_main_list.xml". And the only one that shows up (and is actually related to what I'm trying to do) says "activity_list_item". But I'm not sure if that's the one I should use.

Have you solved it?

Sadly, I haven't. :(

3 Answers

THANK-YOU-SOOOO-MUCH-BEN-YOU-HAVE-NO-IDEA-HOW-FRUSTRATING-THIS-WAS-YOU'RE-A-GOD-SEND :D

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Awesome - so glad I could help! I got a bit behind on support with the holidays and my recording schedule. :)

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Sorry for the delayed response! This was a weird one. (Steve emailed us the project.) There was absolutely no help from Eclipse on where the error was. Usually when the R class won't generate it has something to do with an error in your res directory. Everything looked okay, so I removed all the strings in strings.xml and looked at the errors, because that told me where the strings were being used. Turns out activity_main_list.xml in the menu directory is trying to reference a string resource that doesn't exist:

android:title="@string/menu_settings"

You can change it to @string/action_settings and everything will work. You may need to clean the project after this change, and you will also need to delete the import statement import android.R; in MainListActivity.java.

Oh wait... when you said clean the project, do you mean the little "R cannot be resolved to a variable" errors?

Project > clean project menu should be at the top with file menu and edit and help etc.