Google maps activity crashes after successful installation - android

Not sure why this is happening, the application shows no errors and I've obtained the key successfully as well but the activity doesn't run!
Here is my MapScreen class:
package com.example.prateekchachra.projectconnecttoastmasters;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
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.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
/**
* Created by Prateek Chachra on 5/23/2016.
*/
public class MapScreen extends Activity{
static final LatLng Pos = new LatLng(40, -79);
private GoogleMap googleMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
try {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager()
.findFragmentById(R.id.map)).getMap();
}
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
googleMap.setMyLocationEnabled(true);
googleMap.setTrafficEnabled(true);
googleMap.getUiSettings().setZoomControlsEnabled(true);
Marker marker = googleMap.addMarker(new MarkerOptions().position(Pos).title("That is my loc"));
} catch(Exception e){
e.printStackTrace();
}
}
}
Here is my activity_maps.xml file:
<?xml version = "1.0" encoding = "utf-8" ?>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android" >
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.prateekchachra.projectconnecttoastmasters.MapsActivity" />
</RelativeLayout>
Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.prateekchachra.projectconnecttoastmasters">
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<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="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<permission android:name="com.example.prateekchachra.projectconnecttoastmasters.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="ID" />
<activity
android:name=".MapsActivity"
android:label="#string/title_activity_maps">
</activity>
<activity android:name=".Events"
android:label="Events List">
</activity>
<activity android:name=".FindSlots"
android:label="Find Slots">
</activity>
<activity android:name=".MapScreen"
android:label="Map Main">
</activity>
<activity android:name=".SplashScreen"
android:label="Splash Screen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Logcat Output:
05-24 03:59:40.867 26851-26851/com.example.prateekchachra.projectconnecttoastmasters E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.prateekchachra.projectconnecttoastmasters/com.example.prateekchachra.projectconnecttoastmasters.MapScreen}: android.view.InflateException: Binary XML file line #5: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2343)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
at android.app.ActivityThread.access$600(ActivityThread.java:162)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5371)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #5: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:281)
at android.app.Activity.setContentView(Activity.java:1881)
at com.example.prateekchachra.projectconnecttoastmasters.MapScreen.onCreate(MapScreen.java:34)
at android.app.Activity.performCreate(Activity.java:5122)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395) 
at android.app.ActivityThread.access$600(ActivityThread.java:162) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364) 
at android.os.Handler.dispatchMessage(Handler.java:107) 
at android.os.Looper.loop(Looper.java:194) 
at android.app.ActivityThread.main(ActivityThread.java:5371) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:525) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.ClassCastException: com.google.android.gms.maps.SupportMapFragment cannot be cast to android.app.Fragment
at android.app.Fragment.instantiate(Fragment.java:585)
at android.app.Fragment.instantiate(Fragment.java:560)
at android.app.Activity.onCreateView(Activity.java:4727)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:281) 
at android.app.Activity.setContentView(Activity.java:1881) 
at com.example.prateekchachra.projectconnecttoastmasters.MapScreen.onCreate(MapScreen.java:34) 
at android.app.Activity.performCreate(Activity.java:5122) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395) 
at android.app.ActivityThread.access$600(ActivityThread.java:162) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364) 
at android.os.Handler.dispatchMessage(Handler.java:107) 
at android.os.Looper.loop(Looper.java:194) 
at android.app.ActivityThread.main(ActivityThread.java:5371) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:525) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 
at dalvik.system.NativeStart.main(Native Method) 

Change your android :name in your XML file
android:name="com.google.android.gms.maps.SupportMapFragment"
Replace with your Fragment package and fragment name like
android:name="com.example.prateekchachra.projectconnecttoastmasters.MapScreen"

Related

Google Maps API v2 Android Studio Map not loading

Please keep in mind that I have read through the hundreds of similar questions such as this but I've seemed to cross off the check list of everything that has been stated in the instructions on how to get the Google maps to start working.
First things first, I'll show my code, then I'll narrate what has been happening.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="elephant.tuskapp"
android:versionCode="49"
android:versionName="4.6">
<uses-sdk android:minSdkVersion="15"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<permission android:name="elephant.tuskapp.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="elephant.tuskapp.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.ACCESS_GPS"/>
<uses-permission android:name="android.permission.ACCESS_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.camera.autofocus"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<permission android:name="elephant.tuskapp.permission.C2D_MESSAGE" android:protectionLevel="signature"/>
<uses-permission android:name="elephant.tuskapp.permission.C2D_MESSAGE"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:name=".NVtuskapplication"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name=".activity.MainActivity"
android:label="#string/activity_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<receiver android:name="elephant.tuskapp.service.AlarmReceiver"></receiver>
<receiver android:name="elephant.tuskapp.service.TimeSynchronizer">
<intent-filter>
<action android:name="android.intent.action.ACTION_TIME_CHANGED"/>
<action android:name="android.intent.action.TIMEZONE_CHANGED"/>
</intent-filter>
</receiver>
<service android:name=".service.GPSService"></service>
<service android:name=".service.RouteUpdateService"></service>
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
<receiver
android:name=".service.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<category android:name="elephant.tuskapp"/>
</intent-filter>
</receiver>
<service android:name=".service.GcmIntentService"/>
<meta-data
android:name="io.fabric.ApiKey"
android:value="key" />
<!-- google maps api v2-->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="key"/>
</application>
Layout XML
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
Main Activity
package elephant.tuskapp.activity;
import android.app.Activity;
import android.os.Bundle;
import elephant.tuskapp.R;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.route_details);
}
}
When I run my app, I see a blank canvas with the Google logo on the bottom left corner. The Logcat prints out the following error:
-22 20:47:24.822 22720-22720/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: free.elephant.tuskapp, PID: 22720
java.lang.RuntimeException: Unable to start activity ComponentInfo{free.elephant.tuskapp/elephant.tuskapp.activity.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2301)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2361)
at android.app.ActivityThread.access$800(ActivityThread.java:147)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5232)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:767)
at android.view.LayoutInflater.inflate(LayoutInflater.java:486)
at android.view.LayoutInflater.inflate(LayoutInflater.java:418)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:377)
at android.app.Activity.setContentView(Activity.java:2161)
at elephant.tuskapp.activity.MainActivity.onCreate(MainActivity.java:18)
at android.app.Activity.performCreate(Activity.java:5984)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2254)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2361)
  at android.app.ActivityThread.access$800(ActivityThread.java:147)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loop(Looper.java:135)
  at android.app.ActivityThread.main(ActivityThread.java:5232)
  at java.lang.reflect.Method.invoke(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:372)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
Caused by: java.lang.RuntimeException: API key not found. Check that <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml
at com.google.maps.api.android.lib6.d.fk.a(Unknown Source)
at com.google.maps.api.android.lib6.a.g.a(Unknown Source)
at com.google.android.gms.maps.internal.CreatorImpl.b(Unknown Source)
at com.google.android.gms.maps.internal.CreatorImpl.b(Unknown Source)
at com.google.android.gms.maps.internal.i.onTransact(SourceFile:62)
at android.os.Binder.transact(Binder.java:380)
at com.google.android.gms.maps.internal.zzc$zza$zza.zzr(Unknown Source)
at com.google.android.gms.maps.MapFragment$zzb.zzvu(Unknown Source)
at com.google.android.gms.maps.MapFragment$zzb.zza(Unknown Source)
at com.google.android.gms.dynamic.zza.zza(Unknown Source)
at com.google.android.gms.dynamic.zza.onInflate(Unknown Source)
at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2117)
at android.app.Activity.onCreateView(Activity.java:5333)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:737)
  at android.view.LayoutInflater.inflate(LayoutInflater.java:486)
  at android.view.LayoutInflater.inflate(LayoutInflater.java:418)
  at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:377)
  at android.app.Activity.setContentView(Activity.java:2161)
  at elephant.tuskapp.activity.MainActivity.onCreate(MainActivity.java:18)
  at android.app.Activity.performCreate(Activity.java:5984)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2254)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2361)
  at android.app.ActivityThread.access$800(ActivityThread.java:147)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loop(Looper.java:135)
  at android.app.ActivityThread.main(ActivityThread.java:5232)
  at java.lang.reflect.Method.invoke(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:372)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
Familiar right? You see it in a lot of other questions. I think what differentiates my question from the others is I may have a problem with different flavors of my app.
To cross out the mistakes others have encountered, I have done the following:
- Made sure my api keys are inside the tag of the manifest file.
- Ensured that the Google Maps API v2 for Android is enabled on Google Consoles
- I'm using the Google Play Services via Gradle (Scroll down for my gradle snippet)
- I made sure all of the essential permissions are set
- I made sure to enable the glEsVersion.
What I think the problem is?
I think I'm having a problem with my "free.elephant.tuskapp" flavor to authenticate with googles servers. In my gradle build, I maintain two different flavors of my application and I seem to be getting an error with authentication:
Ensure that the "Google Maps Android API v2" is enabled.
Ensure that the following Android Key exists:
API Key: myAPIKEY
Android Application (<cert_fingerprint>;<package_name>): SHA-1;free.elephant.tuskapp
I obtained my API by using the 'elephant.tuskapp' package name rather than the 'free.elephant.tuskapp'
Here's my gradle build if it's of any help:
Gradle
buildscript {
repositories {
maven {
url 'https://maven.fabric.io/public'
}
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven {
url 'https://maven.fabric.io/public'
}
}
android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc2"
defaultConfig {
applicationId "elephant.tuskapp"
minSdkVersion 15
targetSdkVersion 15
}
productFlavors {
demo {
applicationId "demo.elephant.tuskapp"
}
free {
applicationId "free.elephant.tuskapp"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.google.android.gms:play-services:7.5.0'
compile 'com.google.zxing:core:3.2.0'
compile('com.crashlytics.sdk.android:crashlytics:2.3.2#aar') {
transitive = true;
}
}
Am I missing out on something? Or does it really have something to do with my flavor builds? If it's the flavors causing trouble, how am I supposed to handle this? I generated new api keys for all my flavors but I don't see how I'm supposed to make that work within the manifest file as well as having it look elegant.
According to your logcat, it says something wrong with your Map fragment layout. Also, I find that there is nothing in your MainActivity, I think you should initial map there. For more details, you can refer code here.
Sample code:
public class MainActivity extends FragmentActivity {
GoogleMap mGoogleMap;
private static LatLng MountainView = new LatLng(37.42, -122.08);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initial Map
try {
if (mGoogleMap == null) {
mGoogleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
}
} catch (Exception e) {
e.printStackTrace();
}
mGoogleMap.getUiSettings().setMyLocationButtonEnabled(true);
mGoogleMap.getUiSettings().setZoomControlsEnabled(true);
mGoogleMap.getUiSettings().setZoomGesturesEnabled(true);
mGoogleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(MountainView, 15));
Marker marker = mGoogleMap.addMarker(new MarkerOptions()
.position(MountainView)
.title("Have a nice day!"));
}
}
Since my app has multiple flavors, I was getting thrown an error that my api-keys were not being validated. The way to resolve this is to ensure that you add all packages of your project into the Google Developer Console.
SHA1;packagename
Then press enter
SHA1;packagename2(flavor)
In my case it was:
SHA1;elephant.tuskapp
SHA1;free.elephant.tuskapp
SHA1;demo.elephant.tuskapp

Google Maps api v2 not working and closes unexpectedly

Im almost just a beginner in android. I was trying to make a very simple app with google maps, ie just displaying maps. I followed the following link:
file:///C:/Android/Android%20Google%20Maps%20V2%20Tutorial.htm
But when I test it on my device it says it has stopped working and closes.
Here is my Manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.googleapi"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Required to show current location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.googleapi.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="AIzaSyA5BsIL-3rppsOxQOuX4gBZT3c0cTHNbWc" />
</application>
</manifest>
Acyivity code is: (I tried extending FragementActivity but dosent work with it too.)
package com.example.googleapi;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import android.os.Bundle;
import android.app.Activity;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.widget.Toast;
public class MainActivity extends FragmentActivity {
// Google Map
private GoogleMap googleMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
// Loading map
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* function to load map. If map is not created it will create it for you
* */
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
#Override
protected void onResume() {
super.onResume();
initilizeMap();
}
}
and XML code is( some part of it):
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
My logcat is:
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.app.Activity.setContentView(Activity.java:1929)
at com.example.googleapi.MainActivity.onCreate(MainActivity.java:20)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml
does not have the right value. Expected 4030500 but found 0.
You must have the following declaration within the <application> element:
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
at com.google.android.gms.maps.internal.q.v(Unknown Source)
at com.google.android.gms.maps.internal.q.u(Unknown Source)
at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
at com.google.android.gms.maps.MapFragment$b.cE(Unknown Source)
at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
at com.google.android.gms.dynamic.a.a(Unknown Source)
at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
at android.app.Activity.onCreateView(Activity.java:4785)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
... 21 more
I have googled a lot about it and got some direct questions on it but no answer ?? .
It seems many have the same problem.Can anyone help with this problem. I want to develop an app but not able to proceed as Google mpas api is main part of it.
Your are missing a meta tag in the application tag of manifest
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
You should use SupportMapFragment instead of MapFragment.
Change
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
to
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Change
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
TO
googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(
R.id.map)).getMap();
Whatever you have done is ok with older version of GooglePlayServices, but its apparently visible from your logcat that you are using GooglePlayServices 13 or higher so you need to add the meta data tag in your manifest just the way Raghunandan have answered.

Android Google MapV2 doesn't work on intellijIdea

This is my main class
package com.example.mapv2example;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
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 MyActivity extends FragmentActivity {
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
static final LatLng KIEL = new LatLng(53.551, 9.993);
private GoogleMap map;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
.title("Hamburg"));
Marker kiel = map.addMarker(new MarkerOptions()
.position(KIEL)
.title("Kiel")
.snippet("Kiel is cool")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
// Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Android Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mapv2example"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="17" />
<permission
android:name="com.example.mapv2example.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="com.example.mapv2example.maps.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<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" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
>
<activity
android:name="com.example.mapv2example.MyActivity"
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="MY_API_Key" />
</application>
</manifest>
and the main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
</RelativeLayout>
I am works on IntellijIdea 12 and I add android support library and google play services but when I try to run my app emulator "unfortunately,mapv2example has stopped" I get map version 2 api key from google also this is my error log
12-26 09:03:12.852: ERROR/AndroidRuntime(1714): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mapv2example/com.example.mapv2example.MyActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.mapv2example.MyActivity.onCreate(MyActivity.java:23)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
... 11 more
12-26 09:03:12.996: WARN/ActivityManager(298): Force finishing activity com.example.mapv2example/.MyActivity
12-26 09:03:13.043: WARN/WindowManager(298): Screenshot failure taking screenshot for (328x583) to layer 22010
12-26 09:03:13.652: WARN/ActivityManager(298): Activity pause timeout for ActivityRecord{41896338 u0 com.example.mapv2example/.MyActivity}
12-26 09:03:24.261: WARN/ActivityManager(298): Activity destroy timeout for ActivityRecord{41896338 u0 com.example.mapv2example/.MyActivity}
12-26 09:08:13.061: INFO/Process(1714): Sending signal. PID: 1714 SIG: 9
12-26 09:08:13.071: INFO/ActivityManager(298): Process com.example.mapv2example (pid 1714) has died.
12-26 09:08:13.111: WARN/InputMethodManagerService(298): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy#41c4dd88 attribute=null, token = android.os.BinderProxy#41b7fd80
12-26 09:10:33.132: DEBUG/dalvikvm(435): GC_FOR_ALLOC freed 511K, 19% free 3041K/3752K, paused 540ms, total 540ms
12-26 09:20:33.401: INFO/ActivityManager(298): No longer want com.android.exchange (pid 1420): empty for 1804s
12-26 09:21:33.782: INFO/ActivityManager(298): No longer want com.android.browser (pid 1511): empty for 1810s
12-26 09:21:33.844: INFO/ActivityManager(298): No longer want com.android.calendar (pid 1495): empty for 1811s
12-26 09:21:33.897: INFO/ActivityManager(298): No longer want com.android.sharedstoragebackup (pid 1531): empty for 1809s
12-26 09:21:41.868: DEBUG/GCM(490): Ignoring attempt to send heartbeat on dead connection.
12-26 09:23:08.892: DEBUG/dalvikvm(298): GC_FOR_ALLOC freed 1142K, 38% free 7504K/12064K, paused 113ms, total 128ms
12-26 09:26:45.921: INFO/EventLogService(490): Aggregate from 1388066205680 (log), 1388066205680 (data)
Did you compile properly the google play services in your build.gradle... you can follow the steps at the android developers site... http://developer.android.com/google/play-services/setup.html... and maybe you will have to use the gmaps api v3...
regards...!!

SupportMapFragment not found

I am trying to get Google Maps Android API v2 working on Android 2.2 on a HTC Desire.
My main.xml contains the following:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dk.sw510e13.user"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="dk.sw510e13.user.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>
</application>
</manifest>
This is my activity.
package dk.sw510e13.user;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
public class MainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
#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;
}
}
When I run the application, I will get the following exception. It seems that it cannot find SupportMapFragment, however, I believe that I have both the support library and Google Play Services as dependencies. When creating the project in Android Studio I chose to add support for fragments.
01-17 23:52:55.237 2557-2557/dk.sw510e13.user E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{dk.sw510e13.user/dk.sw510e13.user.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2787)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803)
at android.app.ActivityThread.access$2300(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:144)
at android.app.ActivityThread.main(ActivityThread.java:4937)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:582)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
at android.app.Activity.setContentView(Activity.java:1654)
at dk.sw510e13.user.MainActivity.onCreate(MainActivity.java:13)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
... 11 more
Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
at android.support.v4.app.Fragment.instantiate(Fragment.java:409)
at android.support.v4.app.Fragment.instantiate(Fragment.java:377)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:277)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:558)
... 20 more
Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.SupportMapFragment in loader dalvik.system.PathClassLoader[/data/app/dk.sw510e13.user-2.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
at android.support.v4.app.Fragment.instantiate(Fragment.java:399)
... 23 more
This is what I have in my dependencies.
Can anyone tell me what I am doing wrong?
UPDATE
This is my manifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dk.sw510e13.user"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<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"/>
<!-- The following two permissions are not required to use Google Maps Android API v2, but are recommended. -->
<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"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="dk.sw510e13.user.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="XXXXXX"/>
</application>
</manifest>
This is the problem that seems to be occurred when missing Google Play services.
I request you to please follow the steps mentioned below to get the Google Play services to be included in your application.
copying the google-play-services.jar in libs folder and set in the build path of eclipse is a wrong method.
import Google Play services in your project and add it in workspace.
from location of your SDK folder.
\extras\google\google_play_services\libproject\google-play-services_lib
2! Now you added Google Play Services to your work space, we have to create a reference
from our project to this library. Right-Click your project and choose “Properties” go
to the Android section, in the lower part press the “Add…” button and add a reference
to that library. Your result should be as in the screen shot bellow:
adding Google Play services library
Please Add
<permission
android:name="com.anchit.locationapi.maps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
in your manifest

Google Play Service library and Google Maps

I try to create a simple GoogleMap by Using Google Play Service and Google Maps API. But all the times I get errors...
I´m working with IntelliJ 12.1, here my full Code:
RecorderMap.java
package com.example.GPSApp;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class RecorderMap extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
}
}
map.xml
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.gms.maps.SupportMapFragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.GPSApp"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="16" />
<permission
android:name="com.example.GPSApp.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.newmapview.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<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-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-feature android:name="android.hardware.location.gps" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application android:label="#string/app_name">
<uses-library android:name="com.google.android.maps" />
<activity android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".RecorderMap"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar"/>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="XXX" />
</application>
</manifest>
I think the Problem is how I include the GooGlePlayService... I´ve tried to add as module, as libary as External Libary but I don't know how to include and to use it right... :(
EDIT:
LogCat
08-28 07:41:59.869: ERROR/AndroidRuntime(23080): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.GPSApp/com.example.GPSApp.RecorderMap}: android.view.InflateException: Binary XML file line #2: Error inflating class com.google.android.gms.maps.SupportMapFragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class com.google.android.gms.maps.SupportMapFragment
at android.view.LayoutInflater.createView(LayoutInflater.java:508)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:210)
at android.app.Activity.setContentView(Activity.java:1660)
at com.example.GPSApp.RecorderMap.onCreate(RecorderMap.java:18)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
... 11 more
Caused by: java.lang.NoSuchMethodException: SupportMapFragment(Context,AttributeSet)
at java.lang.Class.getMatchingConstructor(Class.java:643)
at java.lang.Class.getConstructor(Class.java:472)
at android.view.LayoutInflater.createView(LayoutInflater.java:480)
... 20 more
****EDIT2**
Problem solved by using this: java.lang.noclassdeffounderror: com.google.android.gms.R$styleable**
The only thing I find missing in your RecorderMap.java file is that you haven't imported the SupportFragment class. So add this line to it
import com.google.android.gms.maps.SupportMapFragment;
If that doesn't work, then check out the following.
From what you are saying, it means you have already installed the google play services. If not, then try installing it using this link http://developer.android.com/google/play-services/setup.html
After that, referencing the google play services library should be as easy as editing your build.gradle file. The current version of android studio makes this possible. Under dependencies in your build.gradle file, add the following code
compile 'com.google.android.gms:play-services:3.1.36'
You seem to have your API key intact.
Finally, remember you need to test your app on an actual android device and not an emulator. The android API version 2 is not yet able to display maps on emulators.
I think this should be okay for your app to work.

Categories

Resources