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