Jonas Pedersen
Jonas Pedersen

Reputation: 951

Can't find R. layout - app name. Only android layout

For some reason, when i started up eclipse today, it couldn't find my main XML in my

setContentView(R.layout.main);

When i write R. it can only find "Layout - Android.R" - and not my "Layout - com.your.app"

Anyone who knows how to solve this problem?

I just realised my Java file in the /gen folder is missing, how do i retrieve it again?

Cleaning project doesn't work

Upvotes: 3

Views: 20941

Answers (7)

Manisha
Manisha

Reputation: 863

Hi had same problem few minute ago. I kept looking and looking and finally i found out -- >

Its because i was using a file in drawable folder with

1-launch-screen.jpg (Invalid Name for drawable file)

Make sure your file name has valid.

It can not have any '-' character in drawable filename. File name has to be all small letters only.

And that red X mark automatically disappeared and project started top built and i was able to see R.layout.MyNewLayout.

Hope this helps !

Upvotes: 0

Jorgesys
Jorgesys

Reputation: 126455

  • Option 1)Project > Android Tools > Fix Project Properties. Clean and Rebuild your project.

  • Option 2) Refresh your project F5, Delete folders /gen and /bin then Rebuild your project

  • Option 3) update the build tools, some time this will cause a lot of problems and you will have the annoying message related to "Can't find R.layout"

But in this case you wil fix, delete because you don´t need this:

import android.R; 

i think this is your problem.

Folder /gen is automatically generated, but you will solve problems related to resources, probably something missing in your layouts, one of them will have a warning or error.

Upvotes: 2

Changming Shih
Changming Shih

Reputation: 1

I got the same problem with one of my project where I copied an existing XML file (say xmlfile) over. Then, Java file cannot resolve R.layout.xmlfile.

I guess it is probably due to the end of line feed/CR compatibility between Windows and Linux. so, I pruned all the LF/CR and re-saved it on my Mac machine. Then, the problem is resolved.

Upvotes: 0

Marcin Buciora
Marcin Buciora

Reputation: 449

It can be that your project contains errors. To see list of resources it must be able to compile. After that your resources will apear.

Upvotes: 0

Ben Ripley
Ben Ripley

Reputation: 2145

You need to remove the import android.R statement at the top of the file.

See here for more information: http://source.android.com/source/using-eclipse.html

Upvotes: 20

Raghu Nagaraju
Raghu Nagaraju

Reputation: 3288

  1. Try Right click on project > android tools > Fix Project properties
  2. Project > Clean
  3. Project > Build Project

Upvotes: 4

Mohammad Ersan
Mohammad Ersan

Reputation: 12444

check you are importing the current R class, and enable Auto Build under project menu, if enabled, then use clean under the same menu to rebuild the R class

Upvotes: 1

Related Questions