Android Studio - MainActivity.java: error: cannot find symbol - class TextView, class View

Autor BeckyHill
Publikováno 17.05.2020
Kategorie android
Stav Vyřešeno
Dobrý den,

učím se programovat pro Android, používám Android Studio. Mám nějaký java kód - v souboru MainActivity.java mám na začátku tento kód:


public class MainActivity extends AppCompatActivity {

private TextView display;
private View toDeg;
.....


a když to chci spustit, tak mám chybu:


\....\e\MainActivity.java:9: error: cannot find symbol
private TextView display;
^
symbol: class TextView
location: class MainActivity


a další chyby:


\....\e\MainActivity.java:10: error: cannot find symbol
public void toDeg(View sender) {
^
symbol: class View
location: class MainActivity



\....\e\MainActivity.java:29: error: cannot find symbol
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
^
symbol: variable ActivityInfo
location: class MainActivity



\....\e\MainActivity.java:46: error: cannot find symbol
Button btn = (Button) sender;
^
symbol: class Button
location: class MainActivity



\....\e\MainActivity.java:163: error: cannot find symbol
Toast.makeText(this, "Cant do this", Toast.LENGTH_LONG).show();
^
symbol: variable Toast
location: class MainActivity



\....\e\MainActivity.java:263: error: cannot find symbol
DecimalFormat decformat = new DecimalFormat("#.##");
^
symbol: class DecimalFormat
location: class MainActivity


Prosím o pomoc. Děkuji!


Odpovědi na dotaz 2

The English language is translated by machine - the translator can modify eg cited codes = it is better to use codes from the Czech original.

Android Studio - MainActivity.java: error: cannot find symbol - class TextView, class View

Hi,

I'm learning to program for Android, I use Android Studio. I have some java code - in the MainActivity.java file I have this code at the beginning:


public class MainActivity extends AppCompatActivity {

private TextView display;
private View toDeg;
.....


and when i want to run it, i have an error:


\ .... \ e \ MainActivity.java: 9: error: cannot find symbol
private TextView display;
^
symbol: class TextView
location: class MainActivity


and other bugs:


\ .... \ e \ MainActivity.java: 10: error: cannot find symbol
public void toDeg (View sender) {
^
symbol: class View
location: class MainActivity



\ .... \ e \ MainActivity.java: 29: error: cannot find symbol
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
^
symbol: variable ActivityInfo
location: class MainActivity



\ .... \ e \ MainActivity.java: 46: error: cannot find symbol
Button btn = (Button) sender;
^
symbol: class Button
location: class MainActivity



\ .... \ e \ MainActivity.java: 163: error: cannot find symbol
Toast.makeText (this, "Cant do this", Toast.LENGTH_LONG) .show ();
^
symbol: variable Toast
location: class MainActivity



\ .... \ e \ MainActivity.java: 263: error: cannot find symbol
DecimalFormat decformat = new DecimalFormat ("#. ##");
^
symbol: class DecimalFormat
location: class MainActivity


Please help. Thank you!

RE: Android Studio - MainActivity.java: error: cannot…

Autor Hanz
Publikováno 04.06.2020
Kategorie android
Stav Zkontrolováno
Dobrý den,

chyba v Android Studio - "error: cannot find symbol private TextView display;" bude nejspíše znamenat, že nemáte importované nějaké knihovny, měly by stačit tyto:


import android.widget.TextView;
import android.view.View;
import android.content.pm.ActivityInfo;
import android.widget.Button;
import android.widget.Toast;
import java.text.DecimalFormat;


2

The English language is translated by machine - the translator can modify eg cited codes = it is better to use codes from the Czech original.

Android Studio - MainActivity.java: error: cannot find symbol - class TextView, class View

Hi,

error in Android Studio - "error: cannot find symbol private TextView display;" will probably mean that you have not imported any libraries, the following should suffice:


import android.widget.TextView;
import android.view.View;
import android.content.pm.ActivityInfo;
import android.widget.Button;
import android.widget.Toast;
import java.text.DecimalFormat;
Tento web používá k poskytování služeb, personalizaci reklam a analýze návštěvnosti soubory cookie. Používáním tohoto webu s tím souhlasíte. Další informace