0

I am doing a project Android to recreate an application similar to Simon,

I created all the buttons, and thanks to the toast, I can see what they do. my problem is that I cannot generate a random number to the button to start *

I tried to use a random number generator that I found on the internet. but I can not figure out if it works or not because it gives me an error "public final class" saying it can not find it. I tried to create the class file R. but not resolved.

Can anyone help me please?

thx

package com.simonsays;



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

    Button btnStart= (Button)findViewById(R.id.status);
    btnStart.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO genero casualmente il numero. Salvo il colore scelto corrente

            Toast.makeText(MainActivity.this, "sono in start click", Toast.LENGTH_LONG).show();

        }


    });

    Button btnStart1= (Button)findViewById(R.id.green);
    btnStart1.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO genero casualmente il numero. Salvo il colore scelto corrente
            Toast.makeText(MainActivity.this, "sono in green click", Toast.LENGTH_SHORT).show();
        }


    });
    Button btnStart2= (Button)findViewById(R.id.red);
    btnStart2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO genero casualmente il numero. Salvo il colore scelto corrente
            Toast.makeText(MainActivity.this, "sono in red click", Toast.LENGTH_SHORT).show();
        }


    });
    Button btnStart3= (Button)findViewById(R.id.blue);
    btnStart3.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO genero casualmente il numero. Salvo il colore scelto corrente
            Toast.makeText(MainActivity.this, "sono in blue click", Toast.LENGTH_SHORT).show();
        }


    });
    Button btnStart4= (Button)findViewById(R.id.yellow);
    btnStart4.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            Toast.makeText(MainActivity.this, "sono in yellow click", Toast.LENGTH_SHORT).show();
        }


    });

}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}

Machado
  • 14,105
  • 13
  • 56
  • 97
PiBi
  • 39
  • 1
  • 1

2 Answers2

0

R file should be generated automatically by gradle. check your imports, see if R exist.

Build -> Clean Project

usually that do the trick!

JozeRi
  • 3,219
  • 6
  • 27
  • 45
0

Try cleaning your project.

If it doesn't work, check your XML files. Usually R Class errors in Android are generated by them.

You mentioned you want to generate random numbers, but there's nothing else in your code other than onClick events.

Another way around would be checking your imports.

onClick should import View not diaoig.

Machado
  • 14,105
  • 13
  • 56
  • 97