4

I keep getting this when trying to start a new project

ERROR: Unable to open class file C:\Users\Levi\Desktop\Android\workspace\Droid1\gen\com\androidbook\droid1\R.java: No such file or directory

I tried changing preferences to alter build path to project, but it still wouldnt work,,,

Is subfolder on desktop a bad place to install Eclipse?

Gray
  • 108,756
  • 21
  • 270
  • 333
LuxuryMode
  • 31,806
  • 34
  • 112
  • 184
  • Upon restarting Eclipse and clicking this newly created project, the console returns no errors. The file explorer shows all the correct core files and directories. Problem solved....? – LuxuryMode Oct 18 '10 at 11:50
  • Probably replica of http://stackoverflow.com/questions/3796490/error-unable-to-open-class-file-r-java – AZ_ May 23 '11 at 06:44

5 Answers5

5

Clean works sometimes and should be tried. I also find that blowing away the gen directory and refreshing will cause it be to rebuilt. Try that as well.

However, sometimes even that doesn't work and I've been forced to remove the project from Eclipse and then re-import it. This, unfortunately, works for me every time if the above has not.

Good luck.

Gray
  • 108,756
  • 21
  • 270
  • 333
  • what a nightmare it can be when the R. doesn't import.. like wow. talk about walking the line. I found it almost just as fast as troubleshooting the error.. is to rebuild a project from scratch.. and manually import the source...gl – Lenn Dolling Jun 23 '11 at 11:46
2

Im also getting that error, running a Project->Clean in Eclipse helps for me.

Mads Lee Jensen
  • 4,426
  • 5
  • 33
  • 49
2

Project->Clean should certainly fix this (unless your resources won't compile for some seperate reason).

I remember that the first time I ran Eclipse (in mid 2009, can't remember if it was Galileo or Ganymede or whatever) on Windows Vista, it presented several problems that were eventually traced to Eclipse itself being in a directory whose path contained a space...

Reuben Scratton
  • 37,934
  • 8
  • 74
  • 84
  • 1
    Thanks all for the prompt replies. I'm new to android development so I really appreciate any/all help I can get. I apologize in advance if I ask some really noob questions ;) – LuxuryMode Oct 18 '10 at 14:00
  • I am new, too, and I encountered this problem as soon as I finished following the step-by-step for the "Hello, World" in the tutorial. This is definitely a bug in the overall framework (I don't know whether it is in Eclipse or the Android SDK). – Android Eve Nov 11 '10 at 02:21
2

Usually, the above tips (refresh, clean) work for me. But lately I had a very persistant instance of this error, which was caused by something else:

One of the layout .xml files in res/layout contained a reference to a custom view (org.company.project1.MyView). However, I had changed the package path (org.company.project2.MyView), so the reference had become invalid.

Thus, if everything fails try browsing your layout .xml files for invalid custom element definitions.

Cheers

Martin
  • 993
  • 9
  • 6
0

after spending hours trying to ultimatly discover the issue behind the Class Issue not being found, resolved,or directory not there issue....

sometimes yes the issue is due to a bad binary or xml... as sometime a clean will do the trick or a xml edit will solve the day.. when all else fails.... this may do it..

"create a new workspace"

go into the workspace.... and then

Switch to your old workspace... in the newly formed workspace...

this was my silver bullet. so frustrating to not have a solid answer.

using Version: Helios Service Release 2 Build id: 20110218-0911

Lenn Dolling
  • 1,232
  • 13
  • 22