I am creating a simple dice rolling application.
I am getting this error:
cannot resolve method for my nextInt() method and valueOf() method.
I have declared the myResults
variable as an Integer
so I am not sure why I am getting this error. Currently the application should roll a die and return the value. I cannot get to the rest of the logic until I resolve this error. I want to make sure that I can at least get this part running before I continue. The end goal is to roll two die and return the sum of both but I have only coded for one die roll at the moment. Can someone point me in the right direction?
public class MainActivity extends Activity {
// my variables
TextView mText;
ImageButton mButton;
int myResults;
String output;
// function that runs on Start Up
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mText = (TextView)findViewById(R.id.results);
mButton = (ImageButton)findViewById(R.id.roll);
mButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
myResults = new Random(System.currentTimeMillis().nextInt(6)+1);
rollDice();
mText.setText(String.valueOF(myResults));
}
});
}
public void rollDice()
{
switch (myResults)
{
case 1:
mButton.setImageResource(R.drawable.die1);
break;
case 2:
mButton.setImageResource(R.drawable.die2);
break;
case 3:
mButton.setImageResource(R.drawable.die3);
break;
case 4:
mButton.setImageResource(R.drawable.die4);
break;
case 5:
mButton.setImageResource(R.drawable.die5);
break;
case 6:
mButton.setImageResource(R.drawable.die6);
break;
}
}
Once this issue is resolved I would like some guidance on factoring in the second die into myResults. But resolving the methods first would be great.
Error at:
myResults = new Random(System.currentTimeMillis().nextInt(6)+1);
rollDice();
mText.setText(String.valueOF(myResults));