Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

import cannot be resolved

Tags:

android

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.

like image 629
axmug Avatar asked Mar 21 '13 20:03

axmug


People also ask

How do I fix all imports in eclipse?

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.

Why import option is not working in Eclipse?

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.

How do I resolve an error in eclipse?

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.


2 Answers

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

    • Import -> Project -> Android -> Existing Android Code into Workspace , check copy to workspace and browse to where your android sdk folder is located: < android sdk folder>/extras/google/google_play_services/libproject/google-play-services_lib
    • Hit Finish

Project

  • Go to project properties, click on Android, click on Google APIs
  • Modify build path to include the recently added jar (google-play-services-lib.jar) [ located under the bin dir of the google-play-service-lib project]
  • You need to make sure that your app is registered with Google
    • Note your package name for this app
    • In order to get this registered with google, you need to verify your SHA1 certificate fingerprint under < android_sdk>.android as debug.keystore
    • Open a cmd window (Im assuming you are working on windows) browse to C:\Program Files\Java\< JDK version> or where ever java is installed type this as a command to get the SHA1 fingerprint:
    • keytool -list -v -keystore "C:\Program Files (x86)\Android\android-sdk.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android
      • Where the quoted path (need quotes) is the path to your keystore
      • Right click hit "mark" highlight the text after "SHA1:" hit enter to copy

Google APIs Console So with the SHA1 fingerprint copied, you will need to go to https:\code.google.com/apis/console

  • Under "Google apis", click the drop down and hit "Create", name the API project whatever you want.
    • Services should pop up now, scroll down to "Google Maps API v2 or v3" and "Google Maps Android API v2", click the switch for one of them
    • Click on API Access on the left hand side, bringing you to a screen to "Create new Android key"
    • Remember that SHA1: fingerprint you copied? paste it in the both that comes up then < SHA1 fingerprint text>;< package_name as noted before>

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"/>

      • Where the values is from the api console above your SHA1 fingerprint

Its a lot, i realized that, but that is how I used the maps

like image 125
Vnge Avatar answered Oct 03 '22 03:10

Vnge


Try this answer:

The import com.google.android.gms cannot be resolved

  1. 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

  2. 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.

like image 20
user_3068807 Avatar answered Oct 03 '22 03:10

user_3068807