I am using Random() function in my application.When i click on button i have to display a random number in 0-8 range as the text of my button.But when it runs if i click on this button the program will crash.given below is my code snippet.
Random scorenumber=new Random();
OnClickListener clickball=new OnClickListener() {
@Override
public void onClick(View v) {
score=scorenumber.nextInt(8);
id=v.getId();
if(id==R.id.ball2)
{
ball2.setText(score);
}
else if(id==R.id.ball3)
{
ball3.setText(score);
}
}
You are calling
void setText (int resid)here. This will crash when Android does not find a string resource with the same ID as the contents of thescorevariable. UsesetText(Integer.toString(score));.