Android Studio - error: cannot find symbol - setContentView(R.layout.activity_main)

Android Studio - error: cannot find symbol - setContentView(R.layout.activity_main)

Hi,

I'm learning to create something for Android in an Android studio and I'm trying to dissect one finished project to connect an Android application to a MySQL database using RestAPI. However, the application reports an error:


error: cannot find symbol
setContentView(R.layout.activity_main);
^
symbol: variable activity_main
location: class layout


Please help

REPLY


From what I've read, setContentView (R.layout.activity_main) means this:
R - resource
layout - The layout directory
activity_main - activity_main.xml template

But I don't understand why it doesn't work, because the activity_main.xml template is in the correct layout directory ...

However, I managed to solve it and here is the whole process of resolving the errors:


1.)
-------------------------------------------------- ----------------
error: cannot find symbol
getMenuInflater (). inflate (R.menu.menu_activity_main, menu);
^
symbol: variable menu
location: class R


2.)
-------------------------------------------------- ----------------
I added
import android.R;

# new error:
error: cannot find symbol
setContentView (R.layout.activity_main);
^
symbol: variable activity_main
location: class layout


3.)
-------------------------------------------------- ----------------
# I removed
import android.R;
# I gave a Clean project + Rebuild project

4.)
-------------------------------------------------- ----------------
# I added
import cz.muj_balicek.R;

# this returned an error
error: cannot find symbol
getMenuInflater (). inflate (R.menu.menu_activity_main, menu);
^
symbol: variable menu
location: class R

5.)
-------------------------------------------------- ----------------
# I made
res / menu
# and pasted there
menu_activity_main.xml

6.)
-------------------------------------------------- ----------------
# New error
error: cannot find symbol
if (id == R.id.action_settings) {
^
symbol: variable action_settings
location: class id

# I repaired
rest / menu / menu_activity_main.xml


xmlns: app = "http://schemas.android.com/apk/res-auto">
android: id = "@ + id / action_settings"
android: orderInCategory = "100"
app: showAsAction = "never" />




7.)
-------------------------------------------------- ----------------
# another error
error: cannot find symbol
btnSave = (Button) findViewById (R.id.btnSave);
^
symbol: variable btnSave
location: class id

# I added a button to res / layout / edit_product.xml
btn s id btnSave

8.)
-------------------------------------------------- ----------------
Miracle!!! The Android app has finally launched!

Související obsah

android

programovani

android-studio

rest

api

sql

databaze

java

Komentáře

Vaše reakce na Android Studio - error: cannot find symbol - setContentView(R.layout.activity_main)

Reference

Podívejte se na naše reference

Prohlédnout

Aplikace

Podívejte se na naše aplikace

Prohlédnout

Co umíme?

Podívejte se co umíme

Prohlédnout

Co umíme?

Vytváříme sofistikované aplikace pro náročné

Od webových aplikací přes android až po převodové můstky či složité informační systémy.

Podívejte se k nám

Máte ještě čas? Podívejte se na další rubriky

Tento web používá soubory cookie. Dalším procházením tohoto webu vyjadřujete souhlas s jejich používáním.. Více informací zde.