I have an activity class with several imports but some of them are not recognized in Eclipse. I see the error import class name cannot be resolved.
That is my code:
package com.ap.mapa;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapaLugaresActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mapa_lugares);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.mapa_lugares, menu);
return true;
}
}
The errors are in every import com.google.android.gms.maps. If I type another class as import android.content.Context; there are no errors.
How can I fix them?
Thanks.
Go to the line of unused import, press Ctrl + 1, which is an Eclipse shortcut of a quick fix. This will show a drop-down menu to fix this error and one of them will be “remove unused imports.” It will remove that import statement from the Java file.
Go to Preferences » Java » Editor » Content Assist » Advanced. Make sure Other Java Proposals is ticked/checked. If that does not work simply close the project and reopen it.
The Quick Fix dialog can also be displayed by right clicking on the error item in the Problems view and selecting the Quick Fix menu item.
Make sure you have the api version you are using is a Google API as well as having google play services installed
Google Play Services
Open up SDK Manager, scroll to the bottom, expand "Extras", select "Google Play Services", accept and download.
After this is installed, import it into the Workspace
Project
Google APIs Console So with the SHA1 fingerprint copied, you will need to go to https:\code.google.com/apis/console
Go back to the project
Back in Project
Go to the AndroidManifest.xml
Add these permissions to your manifest:
Make sure instead of com.example.androidmapsv2, you match your own package name
<permission
android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE"
android:protectionLevel="signature"></permission>
<uses-permission
android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE"/>
<uses-permission
android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission
android:name="android.permission.INTERNET"/>
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
Under the <application >
tag, add this under it:
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="PASTE YOUR SHA1 CERTIFICATE KEY HERE"/>
Its a lot, i realized that, but that is how I used the maps
Try this answer:
The import com.google.android.gms cannot be resolved
Making a library project using the Google Play jar (in the answer above it uses the maps.jar). I used the same jar as used in the @Vnge's reply i.e < android sdk folder>/extras/google/google_play_services/libproject/google-play-services_lib
After that library project is in the workspace, refer to that project from your current one i.e which is giving errors. The way to do this is provided in the link in my answer. And also @Alex answer in the link.
hope it helps you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With