-1

I'm getting a strange error eclipse says "R cannot be resolved to a variable"

I don't know wath to do.

Do i have to poste my Manifest file? My xml file?

I have tryed : clean project update AVD update SDK

this is my code:

//package

//imports

 public class MainActivity extends Activity implements OnClickListener{

public Handler timer = new Handler();

public int counter = 0;

 //vars

TextView mTextView;
ImageButton finishhimbutton;
ImageButton resetbutton;

 //images

public ImageView jb1;
public ImageView jb2;
public ImageView jb3;
public ImageView jb4;
public ImageView jb5;
public ImageView jb6;
    TextView txtCount;




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

//define

        txtCount = (TextView)findViewById(R.id.timer);              
        txtCount.setText(String.valueOf(counter));
        jb1 = (ImageView) findViewById(R.id.JB1);
        jb2 = (ImageView) findViewById(R.id.JB2);
        jb3 = (ImageView) findViewById(R.id.JB3);
        jb4 = (ImageView) findViewById(R.id.JB4);
        jb5 = (ImageView) findViewById(R.id.JB5);
        jb6 = (ImageView) findViewById(R.id.JB6);

 //click button
        finishhimbutton = (ImageButton) findViewById(R.id.finishhim);
        resetbutton = (ImageButton) findViewById(R.id.reserbutton);
        timer = new Handler();


        final Runnable hMyTimeTask = new Runnable() {
               public void run() {

                    if (counter < 49) {

                    counter = 0;
                    txtCount.setText(String.valueOf(counter));
                    jb1.setVisibility(ImageView.VISIBLE);
                    jb2.setVisibility(ImageView.INVISIBLE);
                    jb3.setVisibility(ImageView.INVISIBLE);
                    jb4.setVisibility(ImageView.INVISIBLE);
                    jb5.setVisibility(ImageView.INVISIBLE);
                    jb6.setVisibility(ImageView.INVISIBLE);
                    }

                   else if (counter > 50) {     
                    Toast.makeText(MainActivity.this, "WINNER", Toast.LENGTH_SHORT).show();

                }
               }

            }; 



        finishhimbutton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                    if (counter == 1) {
                    timer.removeCallbacks(hMyTimeTask);
                    timer.postDelayed(hMyTimeTask, 4000);
                 }

           switch(counter){

     //case's

           case 1:
                    counter++;
                    txtCount.setText(String.valueOf(counter));
                    jb1.setVisibility(ImageView.VISIBLE);
                    jb2.setVisibility(ImageView.INVISIBLE);
                    jb3.setVisibility(ImageView.INVISIBLE);
                    jb4.setVisibility(ImageView.INVISIBLE);
                    jb5.setVisibility(ImageView.INVISIBLE);
                    jb6.setVisibility(ImageView.INVISIBLE);
                    break;

                        //................and more case's
                                //there are more case's


                }

                }


}

);

    //reset button

resetbutton.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
            counter = 0;
            txtCount.setText(String.valueOf(counter));
            jb1.setVisibility(ImageView.VISIBLE);
            jb2.setVisibility(ImageView.INVISIBLE);
            jb3.setVisibility(ImageView.INVISIBLE);
            jb4.setVisibility(ImageView.INVISIBLE);
            jb5.setVisibility(ImageView.INVISIBLE);
            jb6.setVisibility(ImageView.INVISIBLE);
              Intent screen = new Intent(MainActivity.this, startscreen.class);
              MainActivity.this.startActivity(screen);
        }
    });
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public void onClick(View v) {

}
}
Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418
CaptainStony
  • 51
  • 1
  • 8

4 Answers4

2

check if you import android.R and check your xmls for errors and also rebuild all project

Defter
  • 214
  • 1
  • 7
1
  1. close Eclipse and open your Workspace directory.
  2. look for a folder named ".metadata" and delete that folder.

the Error should go away :)

01wifi01
  • 415
  • 6
  • 15
0

1.Remove import android.R; and your main project import.

2.Then go to the error variable and import your project reference.

Afzaal Ahmad Zeeshan
  • 15,669
  • 12
  • 55
  • 103
Sunny
  • 219
  • 1
  • 10
0

I suggest you search Stack Overflow before opening a new report.

This will help :

"R cannot be resolved to a variable"?

Community
  • 1
  • 1
IanB
  • 3,489
  • 1
  • 20
  • 24
  • I don't get it i know the problem but I don't know how to solve it the problem is : R.java don't generate – CaptainStony Jan 17 '14 at 19:33
  • As others have said, this is a very common problem which arises when you make a mistake in your program. For example, it might be an error in one of your xml file. Most Android programmers encounter this from time to time and you should look at the link I provided. – IanB Jan 17 '14 at 23:27