I am trying to make it so that a random number will be generated and displayed and the user will input the number and hit the enter button. If the input text matches the random number generated, it will then do something. However, when I try to use if(message=random)
an error appears saying that "An instance of type 'int' can not be assigned to a variable of type 'java.lang.String'. I do not know what to do or how to fix this.
My code is right here:
Public class MainActivity extends Activity {
/** Called when the activity is first created. */
int random = (int)Math.ceil(Math.random()*100);
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView number = (TextView)findViewById(R.ID.number);
number.setText("" + random);
}
public void enter(View view)
{
EditText answer = (EditText) findViewById(R.id.answer);
String message = answer.getText().toString();
if(message=random)