Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The sample of Google Maps Android API v2 com.example.mapdemo can not find file "R.java"

Today I have read the document of Google Maps Android API v2, it said the project of android-sdk\extras\google\google_play_services\samples\maps can run, but after I imported into eclipse and set the libraries of android-support-v4.jar and google-play-services.jar correctly, import com.example.mapdemo.R; in FeatureView.java (at line 24) can not find the file R.java.

almost all the java file in com.example.mapdemo need class "R", for example, the file BasicMapActivity.java need R in line 41 "setContentView(R.layout.basic_demo);" and line 71 mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();" can someone tell me how to find the class "R"?

R

.java can not create automatically because the file multimap_demo.xml have some errors in
<br><br>    &lt;fragment
<br>      android:id="@+id/map3"
<br>      android:layout_width="match_parent"
<br>      android:layout_height="match_parent"
<br>      android:layout_weight="0.5"
<br>      class="com.google.android.gms.maps.SupportMapFragment"
<br>      map:cameraTargetLat="48.85"
<br>      map:cameraTargetLng="2.35"
<br>      map:cameraZoom="8"/&gt;
<br><br>

eclipse said "cameraTargetLat", "cameraTargetLng" and "cameraZoom" can not recognized. The error information:

Multiple annotations found at this line:
    - error: No resource identifier found for attribute 'cameraTargetLat' in package 'com.example.mapdemo'
    - error: No resource identifier found for attribute 'cameraTargetLng' in package 'com.example.mapdemo'
    - error: No resource identifier found for attribute 'cameraZoom' in package 'com.example.mapdemo'

I do not know why.

If I change the code like this:
<br><br>    &lt;fragment
<br>      android:id="@+id/map3"
<br>      android:layout_width="match_parent"
<br>      android:layout_height="match_parent"
<br>      android:layout_weight="0.5"
<br>      class="com.google.android.gms.maps.SupportMapFragment"/&gt;
<br><br>

the errors disappeared, but i do not know if it can run.

like image 823
user2007659 Avatar asked Jan 24 '13 14:01

user2007659


2 Answers

Copy the maps_attr.xml file from the library project into your project's values folder.

like image 176
droidment Avatar answered Nov 16 '22 06:11

droidment


You should also import google-play-services_lib project (/extras/google/google_play_services/libproject/google-play-services_lib) - after that cameraTargetLat and other ones are recognized and R.java is generated.

like image 34
Oleksandr Avatar answered Nov 16 '22 05:11

Oleksandr