Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R.layout.main cannot be resolved

Using Eclipse on win XP. I've previously created an app or 2, but am now working on the 'real' version and get the above error.

I was having funnies creating a 1.5 version, so have started a new project for 2.1.

package xxx.guest;

import android.R;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

public class briefme extends Activity {

 private String strURL;
           ........
           ........ 

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main ); 

Project as below (note I've removed some names for confidentiality reasons!)

Any ideas what's gone wrong?

Thanks,

Martin.

Project screenshot here

like image 798
Martin Moore Avatar asked Oct 27 '10 15:10

Martin Moore


People also ask

How do I fix R layout?

layout error is being caused by a mismatch between Android Studio's cache and your project's current layout. If you suspect this may be the case, then select File > Invalidate Caches / Restart > Invalidate and Restart from Android Studio's toolbar. Issues with the names of your resources can also prevent the R.

Can t resolve symbol R?

Most often “R cannot be resolved” error appears if there is an issue with some of your resource files. Due to this error, you are unable to build your application. That's why we need to solve this error as it not getting away by just doing a simple restart or hitting Alt+Enter.

What is R layout Main?

R. layout. main - is an integer number implemented in nested layout class of R. java class file. At the run time device will pick up their layout based on the id given in setcontentview() method.

What is SetContentView?

SetContentView(View) Set the activity content to an explicit view. SetContentView(Int32) Set the activity content from a layout resource. SetContentView(View, ViewGroup+LayoutParams)


2 Answers

I would try refreshing. If that doesn't work, close and open the project.

If those two fail, delete and re-create R (it should auto-generate -- copy it just to be on the safe side).

I've had this happen to me a few times and those are the three things I usually do to fix the error.

Also try changing your import:

import android.R;

to:

import your.package.R;
like image 179
James Avatar answered Oct 08 '22 15:10

James


In my case this happened because their was a layout resource with upper case letters in the file name. Resources weren't compiled because of the error and because of that the R class was missing.

like image 29
Michiel van Wessem Avatar answered Oct 08 '22 15:10

Michiel van Wessem