非静态方法' getText()'无法从静态上下文引用

时间:2017-03-10 23:15:33

标签: java android

我无法弄清楚我对这个代码所做的错误是对于一个"更高或更低的游戏"错误

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();
    }
}

}

错误消息在行

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

特别是在getText部分。实际的消息也是标题。

行中还有另一个错误
 } else if (n = number) {

显然它想要一个布尔但得到一个int变量 任何帮助将不胜感激。

0 个答案:

没有答案