0

I am trying to do the tutorial Sample Code from the https://developers.google.com/maps/documentation/android/intro page.I import the google-play-services_lib just fine, then I import the /extras/google/google_play_services/samples/maps

At this point I have 2 errors:

The type android.support.v4.app.Fragment cannot be resolved. It is indirectly referenced from required .class files RetainMapActivity.java /MainActivity/src/com/example/mapdemo line 45 Java Problem

The project was not built since its build path is incomplete.

 Cannot find the class file for android.support.v4.app.Fragment. Fix the build path then try building this project  MainActivity        Unknown Java Problem

I figured this was because I did not yet complete all the steps and continued. When I add android-support-v4.jar via the method in the sample code, I get over 100 errors, all of which look like this (but with different line #s and paths):

R cannot be resolved to a variable  BasicMapActivity.java   /MainActivity/src/com/example/mapdemo   line 42 Java Problem

The only deviation from the tutorial that I took was my android-support-v4.jar was located in sdk\extras\android\support\v4

If there is anything you think I should try, or a bug that you know of, please tell me. Also if there is anymore helpful information I can give, just say so.

Edit: I looked more closely at the code, and there was no R.java in the gen folder. Might explain why nothing could find it.

Community
  • 1
  • 1
user2439231
  • 15
  • 1
  • 6

2 Answers2

1

OK, first of all, know that Eclipse messes up with resources and R.java file many times.

Now,add the android.support.v4 as stated in the tutorials, you'll get your 100+ errors of R cannot be resolved. Now see if import android.R or import package_name.classname.R statement is present anywhere? Please delete these all

Now take a backup of the project somewhere, delete the project and make a new one. Now, copy the folders -- lib/libs, src, res, and Androidmanifest.xml from the backup to the new project folder (replace them). Now refresh the project in eclipse. It should work!

Kunal S. Kushwah
  • 883
  • 1
  • 8
  • 19
  • I could only see 1 import android.R; I deleted it and made a new project. In the new project I get errors in a few of the layouts. It seems to be whenever the layouts use a fragment. Also the auto generated R.java in the new project was removed after I pasted in the src/res/manifest. The errors given are: error: No resource identifier found for attribute 'cameraBearing' in package 'com.example.mapdemo' options_demo.xml /UGH!/res/layout line 17 Android AAPT Problem – user2439231 Jun 05 '13 at 06:44
  • Creating a new id is a process which takes certain time in eclipse. When you create a new id, and "Build automatically" is checked, sometimes Eclipse doesn't pull that id into the R.java file. Trust me, I've come across this many times. may seem childish, but re-follow the procedure. It will solve the issue. – Kunal S. Kushwah Jun 05 '13 at 06:47
  • Should I follow the steps from the original again or from the newly created one? – user2439231 Jun 05 '13 at 06:54
  • I did it with the new one, and the same thing happened. I was able to see that the R.java was deleted right when I pasted the manifest in – user2439231 Jun 05 '13 at 07:01
  • You do not have to paste the code. You have to paste the exact folders in the workspace folder from the backup. Create a new empty project, and build it. paste the foresaid folders into the directory where the project is located on disk (usually the workspace folder). After pasting, refresh the new project in Eclipse. – Kunal S. Kushwah Jun 05 '13 at 07:30
  • I was not pasting the code. I pressed the File>New>Android Application Project. After it creates it I delete the Auto generated src/res/manifest files and copy and past the folders from the backup into the new application folder in the workspace. Is that wrong? – user2439231 Jun 05 '13 at 08:30
  • This is correct. If you get an error that the layout is not fetched, then repeat the above steps, with a change. Turn off "Build automatically" from Project menu. Repeat the above steps, and build your project manually---once after creating a new one, and then after pasting and refreshing. (Caution: Let the refresh process complete itself before you build--see the bottom right corner in Eclipse) – Kunal S. Kushwah Jun 05 '13 at 08:33
0

Try three things

Right click on the map project and under android tools select add support library.

if still not resolved

Select project properties and check android private libraries and android support v4 under the order and export tab

if still not resolved

In the class which is giving error remove the import statement for the R.java file and press ctrl+shift+O then select and import the R file with project name

Ravi
  • 4,872
  • 8
  • 35
  • 46
  • I tried the add support library, and I got the error: The project was not built due to "Could not delete '/MainActivity/bin/classes/com'.". Fix the problem, then try refreshing this project and building it since it may be inconsistent MainActivity Unknown Java Problem I do not see any "classes" in the bin folder, so I don't know what the problem is. Also I do not see a "Order and Export" tab in the Project Properties. And there is not a import statement for the R.Java, nor is there an R.java file in the gen folder – user2439231 Jun 05 '13 at 06:35
  • create a new project and add the support library as told in the answer and the order and export tab is under project propeties and then java build path – Ravi Jun 05 '13 at 10:40