1

I'm dealing with the multiple screen support issue of android applications. To support different screen size, I followed the second answer in this thread, which is creating those folders in the file system.

However I didn't create these folders through eclipse and actually I don't know whether we can do that. I created them directly in file system. And then, I renamed xml files and add one new xml file in the original layout folder. Next I copied the xml files in the original layout folder to each of the new directories. Question is: Is it right steps to create different screen size layouts?

After this, I go to activities (the .java files) to change the layout names, since I renamed the xml files. However I cannot find the renamed files but the original ones. So I followed this thread since I also get the same problem. After doing project->clean, I have error symbol (the red cross) on each of my activities, and turned out in the imports, import com.mylocalname.R; cannot be resolved since R.java is not generated. I didn't import android.R.

According to what I found, R.java is not generated maybe because xml file has some errors. However I cannot see any red cross on those files. So how to fix this problem?

So the project is in a mess now. Does anyone have an idea on how to solve the problem? Thanks a lot in advance.

EDIT:

I'm using android platform 4.1 and API level 16.

The xml files' graphical layouts in the layout folder (not in the layout-X or layout-X-X folders):

graphical layouts

project structures with res expand:

project structure

Community
  • 1
  • 1
Iam619
  • 795
  • 2
  • 12
  • 28
  • I have a very vague memory (year, year and a half ago) of having to temporarily comment out most of my code so that it'd at least compile without the R import. Then do clean, and once Eclipse saw there were no errors anywhere, it'd regenerate R, I could uncomment it all, and it'd work fine. This is not posted as an answer, though, because the memory is so vague, and it feels like I did other stuff to try and fix it at the same time. – Izkata Aug 17 '12 at 15:29
  • @Izkata, I commented most codes and red cross on .java files disappear. However the project still contains errors so it still cannot be built and no R.java is generated. But I don't see other red crosses. I think it must because of the xml files. – Iam619 Aug 17 '12 at 15:59

1 Answers1

1

Did you check the problems view in Eclipse? If one or more XML files have an error in them, it should definitely be on that list.

As far as I can remember XML files will not have a red cross on them like Java files - I can't confirm that right now though. But when you open up the file the error should be displayed in the graphical view and in source view as well (red x next to line with error).

shri046
  • 1,148
  • 11
  • 12
  • Yes, I go to check each of the xml files in all the folders. And the result is: in layout folder, all the xml file cannot have a graphical layout, and what I can see is the picture updated in the question above. There are only yellow triangle (which is a warning I think) in the xml files. While in other folders (layout-X or layout-X-X), I can see the graphical layouts and there are also yellow triangles (since I didn't define some string value in string.xml but directly hard coding them). Thank you very much for helping! – Iam619 Aug 17 '12 at 15:31
  • Can you post a screenshot of the eclipse project structure with the res layout folders expanded? It is hard to visualize without looking at it. The other suggestion I can make is to move your layouts to a different location (like a dummy project) and try pulling them in one by one. – shri046 Aug 17 '12 at 15:36
  • Sure. I've posted it. The res folder contains too many folders that some of them are not shown. But they are all layout-X-X folders like layout-large, layout-large-land, etc. – Iam619 Aug 17 '12 at 15:42
  • The layout looks correct to me. I assume the marker on the src folder is due to the missing R.java file? The one thing I did quickly test is adding a 'layout.bak' folder to a test project. Eclipse gave me this error "invalid resource directory name layout.bak". So that could be part of the problem. Please check your problems view again and post a screenshot of that if possible. Look for any errors other than "R cannot be resolved to a variable". – shri046 Aug 17 '12 at 15:56
  • @Mus that is original layout's back up folder :) – Iam619 Aug 17 '12 at 15:57
  • Copy the files somewhere else (outside eclipse), delete it. Refresh the project and then clean it. – Mus Aug 17 '12 at 15:59
  • @shri046, I delete the layout.bak and the error disappear and I could build the project with most codes commented out. I also commented out the import com.localname.R since it is not generated. And then I add the import com.localname.R back and the R cannot be resolved error comes again, since I still cannot see R generated. Do you have any clue to how to generate R.java in this situation? Thanks a lot! – Iam619 Aug 17 '12 at 16:05
  • @Mus, I did a project clean minutes ago and cannot generate R.java now. Do you know how to re-generate it? Thanks for helping! – Iam619 Aug 17 '12 at 16:06
  • It gets generated automatically by the SDK tools every time the project is build. The only reason why it doesn't get generated AFAIK is when there is an error in any file or if Eclipse thinks there is an error. If you are using the latest ADT plugin, try restarting eclipse. – Mus Aug 17 '12 at 16:08
  • @Mus, I can build the project if I don't import the local R.java file. However once I add the import, it cannot build.... – Iam619 Aug 17 '12 at 16:12
  • @Mus, Ha after I restart eclipse, and build the project without local R.java imported, the project is built, and the R.java is finally generated. And then I add import local R.java back and this time no error symbols on the src files at least. Thanks! – Iam619 Aug 17 '12 at 16:16
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/15473/discussion-between-iam619-and-mus) – Iam619 Aug 17 '12 at 16:16
  • Unfortunately I don't have enough reputation to talk in chat :-) Glad you could get the problem fixed though. – shri046 Aug 17 '12 at 16:20
  • @shri046, Thanks! However the xml files in layout folder still cannot be able to shown in the graphical layout view. Can I ignore it or it is not right? – Iam619 Aug 17 '12 at 16:29
  • @shri046, I delete a custom device screen that I added and then graphical layout is shown again. Also, could you add the remove layout.bak part to your answer above? Since after removing layout.bak, the project is built without local R.java imported. And after restarting Eclipse and build the project, the local R.java is generated, and all the 'import local.R' can be added back without errors. Thanks! – Iam619 Aug 17 '12 at 18:15
  • @shri046, Never mind:) I found I can also edit the answer. Hope you don't mind that I edit it. – Iam619 Aug 17 '12 at 18:28