2016-07-30 105 views
-4

我正在编写一个程序,它从两个文本字段获取两个值并计算其结果。Java:找不到符号类

的问题是,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)); 

    } 
} 
+0

字符串和整数必须以大写字符。你是否用'Import ...'导入了另一个类? – Jens

+2

什么是你的'进口'? –

回答

3

使用以下进口

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