2016-07-30 199 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;