0

I m using google maps v2 and getting this error.

Could not find class 'maps.af.k', referenced from method maps.ag.an.a

I m following all the rules correctly. I have created SHA1 finger print and added it to ANdroid Key for apikey with projct name

1F:41:29:EC:E8:07:3C:A9:F8:6E:EB:D2:7B:42:41:62:3A:36:CA:F2;com.example.routes

Then in mainest file i m using

<fragment
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:id="@+id/map"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/> 

i have also imported the googleplayservices and correctly added it to the project

My code is

public class MainActivity extends FragmentActivity {
GoogleMap googleMap;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    SupportMapFragment fragment = new SupportMapFragment();
    getSupportFragmentManager().beginTransaction()
            .add(android.R.id.content, fragment).commit();
    ;

     googleMap = ((SupportMapFragment)    

  getSupportFragmentManager().findFragmentById(
                R.id.map)).getMap();
  }
}

but still i m getting that error.

mmBs
  • 8,421
  • 6
  • 38
  • 46
  • did u add goolge play services ? – Rat-a-tat-a-tat Ratatouille Oct 16 '13 at 08:06
  • 1
    add fragment code in xml not manifest file and once post your manifest file code – NARESH REDDY Oct 16 '13 at 08:08
  • http://stackoverflow.com/questions/15145789/google-maps-works-fine-on-android-but-i-still-get-an-error-could-not-find-class. similar one – Raghunandan Oct 16 '13 at 08:10
  • @user2842224 Please post your logcat error as well as manifest file. – GrIsHu Oct 16 '13 at 08:13
  • The Error is Could not find class 'maps.af.k', referenced from method maps.ag.an.a and yes i have added google play services. I have added fragment gode in xml only not in manifest – user2842224 Oct 16 '13 at 08:14
  • Have you defined all the required permissions and features in your manifest file ? Also have your enable the service of `Google Maps Android API v2` from google console ? – GrIsHu Oct 16 '13 at 08:17
  • We need your complete code and manifest. Then why are you adding the fragment layout in the manifest? Are you using Eclipse or Android Studio? In which way you've imported Google Play Services in your project? – fasteque Oct 16 '13 at 08:20
  • These are the permissions, com.example.routes.permission.MAPS_RECEIVE,com.example.routes.permission.MAPS_RECEIVE,android.permission.INTERNET,android.permission.WRITE_EXTERNAL_STORAGE,com.google.android.providers.gsf.permission.READ_GSERVICES,android.permission.ACCESS_COARSE_LOCATION,android.permission.ACCESS_FINE_LOCATION in application i have defined meta-data and uses-library – user2842224 Oct 16 '13 at 08:21
  • 1
    Could you please edit your answer with all that info formatted in a proper way? Thanks. – fasteque Oct 16 '13 at 08:25
  • I have imported the google play service from the sdk and and going to project propertie i have added the google play service i m using fragment in layouts and not in manifest file – user2842224 Oct 16 '13 at 08:25
  • i have done this v2 map by this tutorial : http://www.androidhive.info/2013/08/android-working-with-google-maps-v2/ – Tushar Pandey Oct 16 '13 at 08:33

3 Answers3

0

Try to extend Activity rather then FragmentActivity:

  public class MainActivity extends Activity implements LocationListener{
LocationManager locationManager;
    private GoogleMap googleMap;
double lat=17.385044;
double long=78.486671;
 @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
    LocationManager service=(LocationManager)getSystemService(LOCATION_SERVICE);
    locationManager=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
 Criteria criteria = new Criteria();
    provider = locationManager.getBestProvider(criteria, false);
   Location location = locationManager.getLastKnownLocation(provider);
  private void initilizeMap(){
if(googleMap==null){
 googleMap=((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
    //check if map is created succesfully or not
    if(googleMap==null){
Toast.makeText(getApplicationContext(),"sorry unable to create map",1).show();
    }
 } 
MarkerOptions markerOptions=new MarkerOptions().position(new LatLng(lat,long));
markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher));
CameraPosition cameraPosition=new CameraPosition.Builder().target(new LatLng(17.385044,     78.486671)).zoom(12).build();
 googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
 googleMap.setMyLocationEnabled(true);
 googleMap.setOnInfoWindowClickListener(null);
 }

  @Override
  protected void onResume(){
 super.onResume();
 initilizeMap();
   }
  • If i will use Activity and not FragmentActivity , it will not support Gingerbread i.e. supportfragment manager and i have to use it on 2.2 so i need a solution for support fragment manager . – user2842224 Oct 17 '13 at 04:26
  • there is no need to use FragmentActivity it will run on gingerbread – Manpreet Singh Oct 17 '13 at 08:38
0

When you are using SupportMapFragment no need of extending FragmentActivity just extend the Activity See the below example code:

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;

public class MainActivity extends Activity {

private GoogleMap map;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    map =  ((MapFragment)   getFragmentManager().findFragmentById(R.id.map)).getMap();

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}

Note: You have to add google play services library project as a reference to your project, your package name must be com.example.routes you have to add the map fragment in your xml layout not in the manifest. Make following changes to your Manifest.xml Add following permissions.

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

Add the OpenGL

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>

Add the API key

<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="API_KEY"/>

Example manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.package"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="18" />

   <uses-permission android:name="android.permission.INTERNET"/>
   <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
   <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
   <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
   <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<used-feature 
    android:glEsVersion="0x00020000"
    android:required="true"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <activity
        android:name="com.example.package.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="YOUR_API_KEY_HERE"/>
</application>

0

I had the same problem and my solution was to remove and add the googleplayservices again.

Enrico Buß
  • 23
  • 1
  • 7