-1

I am very new to the Android world and Java.

When I try to run this code:

package com.example.firstapp;

import android.os.Bundle;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.view.View;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                TextView textValue = findViewById(R.id.text_value);
                String stringValue = textValue.getText().toString();
                int originalValue = integer.parseInt(stringValue);
                int newValue = MyWorker.doubleTheValue(originalValue);
                textValue.setText(integer.toString(newValue));

                Snackbar.make(view, "Change value " + originalValue + " to " + newValue, Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

I am getting this error:

/Users/pro/AndroidStudioProjects/FirstApp/app/src/main/java/com/example/firstapp/MainActivity.java:29: error: cannot find symbol
                TextView textValue = findViewById(R.id.text_value);
                ^
  symbol: class TextView
/Users/pro/AndroidStudioProjects/FirstApp/app/src/main/java/com/example/firstapp/MainActivity.java:31: error: cannot find symbol
                int originalValue = integer.parseInt(stringValue);
                                    ^
  symbol: variable integer
/Users/pro/AndroidStudioProjects/FirstApp/app/src/main/java/com/example/firstapp/MainActivity.java:33: error: cannot find symbol
                textValue.setText(integer.toString(newValue));
                                  ^
  symbol: variable integer
halfer
  • 19,824
  • 17
  • 99
  • 186
  • There is too much code and not enough context in your question. And please, use a code block to format your errors. Regards – Éric May 17 '20 at 01:38
  • 1
    Have you added corresponding `import` statement for `TextView` to be resolved? – The Godfather May 17 '20 at 08:16
  • You are getting *'cannot find symbol'* errors, not '"symbol" errors', and you are getting them when compiling, not when running. Be complete. Be accurate. – user207421 May 17 '20 at 10:02

1 Answers1

1

It's not a "symbols" error. Let's look at one of them (with a long path cut out):

<somepath>/MainActivity.java:29: error: cannot find symbol
                TextView textValue = findViewById(R.id.text_value);
                ^
  symbol: class TextView

See where it says "error: cannot find symbol". That's the important part. The compiler basically tells you that it doesn't know what you're talking about.

Two symbols can't be found (with the second one happening twice): TextView and integer. The reasons are different:

  • You're missing the import for TextView, add import android.widget.TextView to the top of your file.
  • You've misspelled Integer: it needs to have a capital-I at the beginning.
Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614