FraserOfSmeg FraserOfSmeg - 1 year ago 120
Android Question

Cannot resolve symbol (any ID's) Android Studio

I'm a noob Android studio programmer (this is hour 2 of learning!) and I expect this is a real rookie error I'm making!

I've got a Plain Text field in my application and I would like to set the text of this dynamically. I've given the plain text field the ID of: "resultText". Here's what I try;

public void calcnums(View v)
int x=firstNum + seondNum;
resultText.setText("Result: " + x);

For some reason I get 'resultText' highlighted in red and the hover over message is; Cannot resolve symbol 'resultText'.

I have the feeling that I'm doing something wrong by using the ID, but I'm lost!

Full code as suggested in comments;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import java.util.Random;

public class AddNumbers extends AppCompatActivity {
private int firstNum;
private int seondNum;

protected void onCreate(Bundle savedInstanceState) {

public void calcnums(View v)
int x=firstNum + seondNum;
resultText.setText(String.format("Result: %d", x);
public void setNums(View v)
TextView tx= (TextView) findViewById(;
Random r = new Random();
int x=r.nextInt(2) + 1; // r.nextInt(2) returns either 0 or 1
firstNum = x;
r = new Random();
x=r.nextInt(2) + 1;
seondNum = x;

Answer Source

It seems you need to declare the View resultText


EditText resultText = (EditText) findViewById(;

Also make sure that the name you are using for the resultText View in xml is written correctly as provided in the method findViewById()

usually cannot resolve symbol means some problems in variable declarations.

I am too learning android and I stumbled upon this problem as well.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download