0

Possible Duplicate:
R cannot be resolved - Android error

The errors I have are on line 18 and 19. It does not recognize the id iv1 but that id is in my main.xml file. Also does not recognize the logo_animation which is an xml file and is spelled correctly. Anyone know why this is?

package graphics.examples;

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.ImageView;
import android.graphics.drawable.AnimationDrawable;

public class graphics extends Activity {

AnimationDrawable logoAnimation;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ImageView logoImage = (ImageView) findViewById(R.id.iv1);
    logoImage.setBackgroundResource(R.drawable.logo_animation);
    logoAnimation = (AnimationDrawable) logoImage.getBackground();
}

public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN){
        logoAnimation.start();
        return true;
    }
    else return super.onTouchEvent(event);
    }
}
Community
  • 1
  • 1
John
  • 371
  • 1
  • 4
  • 21
  • Duplicate [http://stackoverflow.com/questions/885009/r-cannot-be-resolved-android-error][1] [1]: http://stackoverflow.com/questions/885009/r-cannot-be-resolved-android-error – Caner Nov 08 '11 at 13:44

4 Answers4

3

It doesn't look like you're importing R. When you add it, make sure you're importing your R file and not android.R

Chris
  • 22,923
  • 4
  • 56
  • 50
0

Do you have invalid XML in some of your files or have you entered ID's in wrong order? Try to remove highlited text/xml in your xml-files and insert them back again and then rebuild the project. I got this problem when I added references to elements/id's in my xml-files that didnt exist yet and when I added the missing elements/id's it still didnt recognize it. So sometimes eclipse is stupid.

Tobias
  • 873
  • 9
  • 17
0

This some times happen because the project was no built, either because you have an error or because you disable automatically build. Only when you built your project the R class is created.

But viewing you code it seems you are missing the import of R package for your project.

It should be something like import graphics.examples.R;

But if you are using eclipse just pass the mouse over the R.id.iv1 and eclipse will show a list of possible imports and choose your package

Pedro Rainho
  • 4,234
  • 1
  • 19
  • 21
0

I run across this problem when there is an error in one of my resource files (layout, drawable, menu). Make sure that you do not have any strings used in the resource files and not declared in the string.xml. I have also had to delete my R.java and when it is recreated the id has been recognized.

jhamm
  • 24,124
  • 39
  • 105
  • 179