I've got an error:
R cannot be resolved to a variable
in line:
setContentView(R.layout.main);
but I can't resolve it doing things that other users wrote should be tried, which are:
layout main.xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
</LinearLayout>
Thanks in advance for your help!
Check your res/
folder in order to be sure that every file it contains has no error. If any error exists R
can not be generated.
Yeah, i got stuck on this for hours. My solution was to: delete all projects from workspace->re-import the desired project by going to file->import->Browse->selecting the project->and finally check the "add project to working sets box" then clicking finish. The .R errors i once had then disappeared. I hope this helps someone!
Don't import Android.R;
instead,
import package.name.R;
where package.name
is your package name declared in the manifest.
Android.R
contains all the default layouts packaged with Android. Your custom layout will not be Android.R
, it will be in package.name.R;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With