0

i know this question been asked before but i didn't find the solution yet, i wrote an android app but it didn't work and i don't know what is the problem, i almost try any thing so please help !!

this is my code :

MainActivity java:-

package com.startPoint.gmap;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;



public class MainActivity extends FragmentActivity {

private GoogleMap map;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    map=((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

    map.setMapType(GoogleMap.MAP_TYPE_NORMAL);

 }
}

Manifest:-

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

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

<permission android:name="com.startPoint.gmap.MAPS_RECEIVE" android:protectionLevel="signature"></permission>
<uses-permission android:name="com.startPoint.gmap.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="com.startPoint.gmap.providers.gsf.permissions.READ_GSEREVICES"/>

<uses-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.startPoint.gmap.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="API KEY HERE"/>
</application>

activity_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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.startPoint.gmap.MainActivity$PlaceholderFragment" >

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

</RelativeLayout>

and this is the error i get:-

03-24 03:25:13.935: D/AndroidRuntime(12021): Shutting down VM
03-24 03:25:13.935: W/dalvikvm(12021): threadid=1: thread exiting with uncaught exception (group=0x41cda700)
03-24 03:25:13.940: E/AndroidRuntime(12021): FATAL EXCEPTION: main
03-24 03:25:13.940: E/AndroidRuntime(12021): java.lang.RuntimeException: Unable to start  activity ComponentInfo{com.startPoint.gmap/com.startPoint.gmap.MainActivity}:  android.view.InflateException: Binary XML file line #11: Error inflating class fragment
03-24 03:25:13.940: E/AndroidRuntime(12021):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
03-24 03:25:13.940: E/AndroidRuntime(12021):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
03-24 03:25:13.940: E/AndroidRuntime(12021):    at android.app.ActivityThread.access$700(ActivityThread.java:159)
03-24 03:25:13.940: E/AndroidRuntime(12021):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
03-24 03:25:13.940: E/AndroidRuntime(12021):    at android.os.Handler.dispatchMessage(Handler.java:99)
03-24 03:25:13.940: E/AndroidRuntime(12021):    at android.os.Looper.loop(Looper.java:176)
03-24 03:25:13.940: E/AndroidRuntime(12021):    at android.app.ActivityThread.main(ActivityThread.java:5419)
03-24 03:25:13.940: E/AndroidRuntime(12021):    at java.lang.reflect.Method.invokeNative(Native Method)
03-24 03:25:13.940: E/AndroidRuntime(12021):    at java.lang.reflect.Method.invoke(Method.java:525)
03-24 03:25:13.940: E/AndroidRuntime(12021):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
03-24 03:25:13.940: E/AndroidRuntime(12021):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
03-24 03:25:13.940: E/AndroidRuntime(12021):    at dalvik.system.NativeStart.main(Native Method)
03-24 03:25:13.940: E/AndroidRuntime(12021): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
03-24 03:25:13.940: E/AndroidRuntime(12021):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:719)
03-24 03:25:13.940: E/AndroidRuntime(12021):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
03-24 03:25:13.940: E/AndroidRuntime(12021):    at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
03-24 03:25:13.940: E/AndroidRuntime(12021):    at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
03-24 03:25:13.940: E/AndroidRuntime(12021):    at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
03-24 03:25:13.940: E/AndroidRuntime(12021):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:361)
03-24 03:25:13.940: E/AndroidRuntime(12021):    at android.app.Activity.setContentView(Activity.java:1956)
03-24 03:25:13.940: E/AndroidRuntime(12021):    at com.startPoint.gmap.MainActivity.onCreate(MainActivity.java:17)
03-24 03:25:13.940: E/AndroidRuntime(12021):    at android.app.Activity.performCreate(Activity.java:5372)
03-24 03:25:13.940: E/AndroidRuntime(12021):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
03-24 03:25:13.940: E/AndroidRuntime(12021):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
03-24 03:25:13.940: E/AndroidRuntime(12021):    ... 11 more
03-24 03:25:13.940: E/AndroidRuntime(12021): 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" />
03-24 03:25:13.940: E/AndroidRuntime(12021):    at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
03-24 03:25:13.940: E/AndroidRuntime(12021):    at  com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
03-24 03:25:13.940: E/AndroidRuntime(12021):    at com.google.android.gms.maps.internal.q.v(Unknown Source)
03-24 03:25:13.940: E/AndroidRuntime(12021):    at com.google.android.gms.maps.internal.q.u(Unknown Source)
03-24 03:25:13.940: E/AndroidRuntime(12021):    at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
03-24 03:25:13.940: E/AndroidRuntime(12021):    at com.google.android.gms.maps.SupportMapFragment$b.cE(Unknown Source)
03-24 03:25:13.940: E/AndroidRuntime(12021):    at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
03-24 03:25:13.940: E/AndroidRuntime(12021):    at com.google.android.gms.dynamic.a.a(Unknown Source)
03-24 03:25:13.940: E/AndroidRuntime(12021):    at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
03-24 03:25:13.940: E/AndroidRuntime(12021):    at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
03-24 03:25:13.940: E/AndroidRuntime(12021):    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290)
03-24 03:25:13.940: E/AndroidRuntime(12021):    at     android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
    03-24 03:25:13.940: E/AndroidRuntime(12021):    ... 21 more

i found in the CatLog that i should add the following permission in the manifiest

<meta-data android:name="com.google.android.gms.version"

so i did but i still have an error but the CatLog is different is it the same old problem or not ??

new LogCat

04-07 20:05:37.830: I/Google Maps Android API(26532): Google Play services client version: 4030500
04-07 20:05:37.880: I/Google Maps Android API(26532): Google Play services package version: 4324036
04-07 20:05:38.825: D/dalvikvm(26532): GC_FOR_ALLOC freed 554K, 15% free 9888K/11632K, paused 42ms, total 43ms
04-07 20:05:38.930: D/dalvikvm(26532): GC_FOR_ALLOC freed 191K, 15% free 9944K/11632K, paused 17ms, total 17ms
04-07 20:05:38.930: I/dalvikvm-heap(26532): Grow heap (frag case) to 10.884MB for 18832-byte allocation
04-07 20:05:38.950: D/dalvikvm(26532): GC_FOR_ALLOC freed 0K, 15% free 9962K/11652K, paused 18ms, total 18ms
04-07 20:05:39.170: D/dalvikvm(26532): GC_FOR_ALLOC freed 69K, 14% free 10238K/11880K, paused 30ms, total 30ms
04-07 20:05:39.720: D/AbsListView(26532): Get MotionRecognitionManager
04-07 20:05:39.755: D/AbsListView(26532): onVisibilityChanged() is called, visibility :  8
04-07 20:05:39.755: D/AbsListView(26532): unregisterIRListener() is called 
04-07 20:05:39.760: D/AbsListView(26532): onVisibilityChanged() is called, visibility : 8
04-07 20:05:39.760: D/AbsListView(26532): unregisterIRListener() is called 
04-07 20:05:39.760: D/AbsListView(26532): onVisibilityChanged() is called, visibility : 0
04-07 20:05:39.760: D/AbsListView(26532): unregisterIRListener() is called 
04-07 20:05:39.970: D/AndroidRuntime(26532): Shutting down VM
04-07 20:05:39.970: W/dalvikvm(26532): threadid=1: thread exiting with uncaught exception (group=0x41c21700)
04-07 20:05:40.000: E/AndroidRuntime(26532): FATAL EXCEPTION: main
04-07 20:05:40.000: E/AndroidRuntime(26532): java.lang.RuntimeException: Unable to start  activity ComponentInfo{com.startPoint.gmap/com.startPoint.gmap.MainActivity}: java.lang.NullPointerException
04-07 20:05:40.000: E/AndroidRuntime(26532):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
04-07 20:05:40.000: E/AndroidRuntime(26532):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
04-07 20:05:40.000: E/AndroidRuntime(26532):    at android.app.ActivityThread.access$700(ActivityThread.java:159)
04-07 20:05:40.000: E/AndroidRuntime(26532):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
04-07 20:05:40.000: E/AndroidRuntime(26532):    at android.os.Handler.dispatchMessage(Handler.java:99)
04-07 20:05:40.000: E/AndroidRuntime(26532):    at android.os.Looper.loop(Looper.java:176)
04-07 20:05:40.000: E/AndroidRuntime(26532):    at android.app.ActivityThread.main(ActivityThread.java:5419)
04-07 20:05:40.000: E/AndroidRuntime(26532):    at java.lang.reflect.Method.invokeNative(Native Method)
04-07 20:05:40.000: E/AndroidRuntime(26532):    at java.lang.reflect.Method.invoke(Method.java:525)
04-07 20:05:40.000: E/AndroidRuntime(26532):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
04-07 20:05:40.000: E/AndroidRuntime(26532):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
04-07 20:05:40.000: E/AndroidRuntime(26532):    at dalvik.system.NativeStart.main(Native Method)
04-07 20:05:40.000: E/AndroidRuntime(26532): Caused by: java.lang.NullPointerException
04-07 20:05:40.000: E/AndroidRuntime(26532):    at com.startPoint.gmap.MainActivity.onCreate(MainActivity.java:20)
04-07 20:05:40.000: E/AndroidRuntime(26532):    at android.app.Activity.performCreate(Activity.java:5372)
04-07 20:05:40.000: E/AndroidRuntime(26532):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
04-07 20:05:40.000: E/AndroidRuntime(26532):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
04-07 20:05:40.000: E/AndroidRuntime(26532):    ... 11 more

2 Answers2

0

You need to add the following to your manifest file under your <application> tag:

<meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />

Edit Assuming that you have your Google Play Services correctly set up, you could run a check when your activity is loaded to see that it is accessibe.

int errorCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
        if (errorCode == ConnectionResult.SUCCESS) {

            // ** GO TO YOUR MAP HERE

            FragmentTransaction transaction = getFragmentManager().beginTransaction();
            MyFragment myMapFragment = new MyFragment();
            transaction.replace(R.id.your_fragment_holder, myMapFragment, "MAP").commit();

        } else {
            Dialog theDialog = GooglePlayServicesUtil.getErrorDialog(errorCode, this, 1);
            theDialog.setTitle("Map update required");
            theDialog.setCancelable(true);
            theDialog.setOnCancelListener(new OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {

                    //** HANDLE WHEN USER HAS NO MAPS AVAILABLE

                    FragmentTransaction transaction = getFragmentManager().beginTransaction();
                    NonMapFragment myNonMapFragment =  new NonMapFragment();
                    transaction.replace(R.id.my_fragment_manager, myNonMapFragment, "NOTAMAP").commit();
                }
            });
            theDialog.show();
        }

This will at least check whether the device is able to work with Maps.

CodeMonkey
  • 1,426
  • 1
  • 14
  • 32
  • i did what you say, still have the same problem – user3453634 Mar 24 '14 at 07:07
  • The SAME problem? Your error should not be stating `Expected 4030500 but found 0` with that line of code. Could you update your LogCat? – CodeMonkey Mar 24 '14 at 22:08
  • have you included [Google Play Services](http://developer.android.com/google/play-services/setup.html) in your project correctly? – CodeMonkey Mar 24 '14 at 22:11
  • i updated my logcat .. if it is impossible to be solved can you provide me with working code. because i work on my graduation project and time is luxعry i can't provide. – user3453634 Mar 25 '14 at 09:47
  • i tried the code on other two devices and also have the same problem,so i don't think the issue is on my device – user3453634 Mar 26 '14 at 01:27
  • can you tell me what is the problem exactly ?? – user3453634 Mar 29 '14 at 04:19
  • Do you actually have an API key in the manifest under ``? Just trying to cover off all possibilities. You need to have a maps API key inserted where it says `"API KEY HERE"`. – CodeMonkey Mar 30 '14 at 22:09
  • Well, the problem seems to be pointing towards an incorrect setup for Google Play Services. `@integer/google_play_services_version` is a reference to a value in the Google Play library. [This is an example](http://stackoverflow.com/a/19844573/716588) of someone with a similar problem which was sourced to an incorrect Play Services setup. Failing that, you could try and remove the Play Services lib ans start from scratch, following the guide in my previous comment. – CodeMonkey Apr 01 '14 at 04:09
0

Here your minimum SDK version is 18. So you need to use

android:name="com.google.android.gms.maps.MapFragment"

instead of

android:name="com.google.android.gms.maps.SupportMapFragment"

in your xml file for fragment.

After that your logcat clearly says that you haven't set google_play_services_version between < application> tag. So you need to use this.

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

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

<permission android:name="com.startPoint.gmap.MAPS_RECEIVE"  android:protectionLevel="signature"></permission>
<uses-permission android:name="com.startPoint.gmap.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="com.startPoint.gmap.providers.gsf.permissions.READ_GSEREVICES"/>

<uses-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.startPoint.gmap.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="API KEY HERE"/>

 <meta-data
  android:name="com.google.android.gms.version"
  android:value="@integer/google_play_services_version" />
</application>

Also change here from

  map=((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

to

  map=((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
Piyush
  • 18,895
  • 5
  • 32
  • 63