1

OK, I have a question I'm too confused to ask properly but here's a go:

Somewhere in the android documentation it states:

Note: Eclipse sometimes likes to add an "import android.R" statement at the top of your files that use resources, especially when you ask eclipse to sort or otherwise manage imports. This will cause your make to break. Look out for these erroneous import statements and delete them.

I've noticed this behavior before. The first time was a very bad experience because I couldn't understand what was going on. Anyway since then whenever I notice import android.R; I just delete it.

My most recent project used the latest SDK including the Master - Detail Activity wizard (that creates fragments). I noticed in my ListFragment source file import android.R; and then deleted it which broke it because it apparently needs android.R to use the built in layout "simple_list_item_activated_1" (http://developer.android.com/reference/android/R.layout.html#simple_list_item_activated_1) in onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setListAdapter(new ArrayAdapter<DummyContent.DummyItem>(getActivity(),
            R.layout.simple_list_item_activated_1,
            R.id.text1,
            DummyContent.ITEMS));
}

So I add it back and it's fine. The problem is with android.R included I can't see any of my defined XML stuff. In my case I'm trying to use a menu I created in onCreateOptionsMenu.

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    //MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_checklist_list, menu);
    R.layout.
}

So my problem is if I don't import android.R then onCreate is broke if I do import android.R then onCreateOptionsMenu is broke. Damned if I do, damned if I don't. cries

:'(

Geeks On Hugs
  • 1,591
  • 2
  • 18
  • 31

1 Answers1

5

This will usually happen because:

  1. Eclipse with ADT has a few bugs.
  2. You are using an R resource from the android.R file.

To fix this, remove the import android.R statement. Now some errors will go, and if the error was because of #2, some new ones will come up. Scroll to the new errors. They should be lines like:

R.layout.simple_list_item_activated_1

Now simply prefix android. to that R variable, and the error will go away.

Also, you should clean the project every time an error related to the R file happens.

Raghav Sood
  • 81,899
  • 22
  • 187
  • 195