Search code examples
androidimageviewr.java-filefindviewbyid

Android imageView id not showing


I have an imageView in my main.xml file, that isn't setup with a source initially. I want to be able to dynamically change the image resource within the code. so lets so i have my imageView setup like this:

            <ImageView
            android:id="@+id/countryImage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@string/CountryImageContent"/>

So i try to access within my code like this:

ImageView img = (ImageView) findViewById(R.id.countryImage);

The problem is here. Eclipse is giving me an error saying that "countryImage cannot be resolved or is not a field". A quick peek into my R.java file is showing me that the imageView isn't actually in there. Why is this happening? Thanks.


Solution

  • look into your drawable and layout if there is any error

    if not try cleaning your project

    Go to Project > clean > select your project

    if not then look into your imports for

    your.packagename.R remove it