0

Hi guys :) I found similar topics here about Force Closing applications in Android when using Google Map API. I tried almost everything, followed tutorials step by step and checked more than twice - everytime something goes wrong and my application crashes instantly. I am not able to run even an example code from Google. I tried on emulator distributed with SDK, Genymotion, my HTC One X - all times the same crash: "Unfortunately, GMapsTest application has stopped". Here's my logcat, maybe there's something I don't see.

Logcat: http://pastebin.com/dXk6X31t AndroidManifest: http://pastebin.com/WTNH7M2p Java code: http://pastebin.com/JwzV1Vry XML Layout: http://pastebin.com/eUX8Hgdy

Thanks for any help!! :D

pablo7890
  • 65
  • 9

2 Answers2

1

The problem is in the manifest file. Make sure the add the following meta-data tag inside the application tag

<meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version"
        />
Or Bar
  • 1,566
  • 11
  • 12
  • That's it :) you beat me to it – KickAss Dec 29 '13 at 22:57
  • Thanks. I tried that, alsow failing.. eh. I reinstalled app completely - the same. I want just the another error to appear, this one is boring.. :P I also played with Order in Java Build Path, nothing helped. – pablo7890 Dec 30 '13 at 11:31
0

Full Edit

Fragment Activity class:

import android.annotation.SuppressLint;
import android.graphics.Canvas;
import android.graphics.RectF;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.Fragment;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.UiSettings;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapController;

public class Main extends FragmentActivity{

private GoogleMap mMap;

UiSettings settings;
MapController mapController;
GeoPoint geopoint;
RectF oval;
Canvas canvas;
int mRadius = 5;

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    setUpMap();
}

@Override
protected void onResume(){
    super.onResume();
    setUpMap();
}

private void setUpMap(){
    if (mMap != null) {
        return;
    }
    mMap=((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.myMapView)).getMap();
    if (mMap == null) {
        return;
    }

    mMap.setTrafficEnabled(true);
    mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);

}

}

Layout file activity_maps:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#ffffff" >

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

</RelativeLayout>

Finally to manifest file add:

<permission
     android:name="your_package.permission.MAPS_RECEIVE"
     android:protectionLevel="signature"/>

<uses-permission android:name="your_package.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<application
    android:allowBackup="true"
    android:icon="@drawable/logo"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" android:debuggable="false">

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


    <activity.....
    </activity>
</application>

Finally right click into your project --> Android --> Add google-play-services_lic to your project as reference. This codes copied from a published project. So this is working for me.

Batuhan Coşkun
  • 2,961
  • 2
  • 31
  • 48
  • Hello. Thank you for your time. I did what you said, but with no result. Still crashing in the same way, here's new logcat http://pastebin.com/fTxHYiFf Perhaps could you create simple project in eclipse with simplest map, and share with me? I would really appreciate this. I'm so confused with this API :( – pablo7890 Dec 30 '13 at 14:47
  • Check the edited answer bro. All i can do is this. Copied from published project.@pablo7890 – Batuhan Coşkun Dec 30 '13 at 15:10
  • Dammit, it's not working :( I don't know what is wrong.. Maybe eclipse is responsible for this? Java compiler? Or something else? What else IDEs do you prefer? Now I have the latest ADT and you see how it works for me :( Here's my project based literally on your answer: https://www.dropbox.com/s/pltthlx1r47rhtg/TheLastOne.zip – pablo7890 Dec 30 '13 at 18:47
  • What is the problem? i checked your project and no error with that. You have a null map with a gray background ha? – Batuhan Coşkun Dec 30 '13 at 20:43
  • You run the project on emulator? – Batuhan Coşkun Dec 30 '13 at 20:45
  • You ran my project succesfully?? I'm trying on my htc one x, genymotion and avd emulator with no damn positive.. Everytime: "Unfortunately, TheLastOne has stopped." What did you use? Eclipse from ADT? Ehh, finally some good news! :D Thanks! – pablo7890 Dec 30 '13 at 21:31
  • This project is working, but no map display shown on the screen. You have an authorization failure about the api-key. You must follow right tutorial for this. – Batuhan Coşkun Dec 31 '13 at 06:48
  • You can check my accepted answer about this topic. [Link of my answer](http://stackoverflow.com/questions/20550783/api-key-android-make-couldnt-get-connection-factory-client/20562326#20562326) – Batuhan Coşkun Dec 31 '13 at 06:59
  • Hello again. I did exactly what was in these tutorials. Now, I have release API Key, but the app is still 'unfortunatelly' stopping. Here's new logcat: http://pastebin.com/qdkXk5mk and here is signed apk with release api key: https://www.dropbox.com/s/jkpt5wy1awcggnv/TheLastOneN.apk Maybe you can try it yourself, on my htc and emulators I got same crashes as before.. Well, if you got in mind any idea, please tell me :) Thanks again, pablo7890 – pablo7890 Jan 01 '14 at 12:02