0

I can't figure out what I've done wrong with this code for a "Higher or lower game" error below

package com.test.higherorlower;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import java.util.Random;

public class MainActivity extends AppCompatActivity {

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


}



public void guess(View view) {

    Random rand = new Random();
    int n = 0;


    EditText guess = (EditText) findViewById(R.id.number);

    int number = Integer.parseInt(EditText.getText().toString());

    if (number > 20) {
        Toast.makeText(com.lastineindustries.higherorlower.MainActivity.this, "That number is above 20.", Toast.LENGTH_LONG).show();
    } else if (number < 0) {
        Toast.makeText(com.lastineindustries.higherorlower.MainActivity.this, "That number is negative.", Toast.LENGTH_LONG).show();
    } else if (n > number) {
        Toast.makeText(com.lastineindustries.higherorlower.MainActivity.this, "Higher.", Toast.LENGTH_LONG).show();
    } else if (n < number) {
        Toast.makeText(com.lastineindustries.higherorlower.MainActivity.this, "Lower.", Toast.LENGTH_LONG).show();
    } else if (n = number) {
        Toast.makeText(com.lastineindustries.higherorlower.MainActivity.this, "Correct.", Toast.LENGTH_LONG).show();
    }
}

}

error message is in the line

int number = Integer.parseInt(EditText.getText().toString());

specifically in the getText part. The actual message is also the title. There is also another error in the line

 } else if (n = number) {

apparently it wants a Boolean but got an int variable any help would be greatly appreciated.

Kyle James
  • 13
  • 1

0 Answers0