Arslan Ahmed Awan Arslan Ahmed Awan - 4 months ago 24
Java Question

Java _ Cannot Find Symbol Class

I am Write a Program that gets two values from two text fields and calculates their result.

The problem, I am facing is that Java Editor Shows me the following errors.

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


My Code is .........

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

}
}

Answer

use following imports

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