1

This code is from an exercise source code from a course I took. It worked fine up until this afternoon. No change was made to it and I re imported it and a similar project and experienced the same new error.

public class TourListAdapter extends ArrayAdapter<Tour> {
    Context context;
    List<Tour> tours;


    public TourListAdapter(Context context, List<Tour> tours) {
        super(context, android.R.id.content, tours);
        this.context = context;
        this.tours = tours;
    }

I'm using Android Studio 1.3

android.R.id.content used to work and now generates the error:

Expected resource of type layout.

I've searched stackoverflow and there appears to be a new feature that annotates possible mis-matches. Somehow this android id integer used to be ok and is not any longer. I did not download anything new today to Android Studio.

I have re-built, cleaned and sycn'd. I have exited and rebooted the computer with no resolution.

rekire
  • 47,260
  • 30
  • 167
  • 264
dhd1956
  • 11
  • 3
  • Welcome to SO. I've edited the question by deleting useless tag, in this case *R* which seems to do not belong to your question (I suppose android development). Next time be more careful thank you and welcome again. – SabDeM Aug 16 '15 at 17:22
  • have you imported any R.java files..please check your imports.. – Lal Aug 16 '15 at 17:23
  • I have not imported any R.java files. – dhd1956 Aug 16 '15 at 17:36

1 Answers1

0

It's not an error, it's simply a warning.

As you've noted in your question, resource method parameters can now be annotated to indicate what type of resource should be passed to it. Android Studio checks these parameters based upon the name and flags it if it doesn't match the correct type.

However, you've stumbled upon a corner-case that Android Studio does not deal with. As noted by this question, android.R.id.content is a special resource ID used to obtain a root view without knowing the actual ID of the view. Sadly, the Android SDK developers put it as an id resource and not as a layout resource (it should probably have been designated android.R.layout.content, but it's too late to change it now!).

So, to sum up, Android Studio is expecting you to use a R.layout.value here, but you are using a special R.id.value. But you are correct and your App should still build correctly (mine does when I tested it) - hence it is a warning, not an error.

Community
  • 1
  • 1
adelphus
  • 10,116
  • 5
  • 36
  • 46