Java:找不到符号类

时间:2016-07-30 09:02:10

标签: java android android-studio

我正在编写一个程序,它从两个文本字段中获取两个值并计算它们的结果。

问题是Java编辑器向我显示以下错误:

cannot find symbol class EditText
cannot find symbol class Button
cannot find symbol class string
cannot find symbol class variable integer
cannot find symbol class integer

这是我的代码:

public class MainActivity extends AppCompatActivity
{
    EditText firstNumber;
    EditText secondNumber;
    Button btnAdd;
    TextView total;


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

        firstNumber = (EditText)findViewById(R.id.firstNumber);
        secondNumber = (EditText)findViewById(R.id.secondNumber);
        btnAdd = (Button)findViewById(R.id.btnAdd);
        total = (TextView)findViewById(R.id.total);
  }

    public void btnAdd_Click(View view)
    {
        string getfirstNumber = firstNumber.getText().toString();
        string getsecondNumber = secondNumber.getText().toString();
integer totalResult = integer.parseInt(getfirstNumber) + integer.parseInt(getsecondNumber);
total.setText("Total = " + integer.toString(totalResult));

    }
}

1 个答案:

答案 0 :(得分:3)

使用以下导入

import android.widget.Button;
import android.widget.EditText;