3

I am developing a simple application to show a map. For this i am testing my application on a real device as: Samsung Galaxy Europa (Android 2.2). Unfortunately my application is being closed/crashed forcely with lots of errors being viewed in logcat (i am mentioning along with my code). I have included google_play_services_lib as per the rules but in-vain. And Yes i have scratched every bit of solutions mentioned here like:

  1. Solution 1 - Google play services out of date
  2. Solution 2 - Google play services out of date
  3. Solution 3 - Google play services out of date
  4. Solution 4 - Google play services out of date
  5. Solution 5 - Google play services out of date
  6. Solution 6 - Google play services out of date
  7. Solution 7 - Null pointer exception calling fragment

But applying these out of so many other solution didn't come to fruition. And my application is still crashing. I have even tested my application on online Manymo emulator but my application is crashing there as well on emulator. Is only my google play services version a cause that is not letting my app to run or something else? I am going to put my code and every other bit so you guys can have a look to dig-out the root cause.

MainActivity.java

package com.example.googlev2map;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import android.os.Bundle;
import android.app.Activity;
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.activity_main);


        GoogleMap googleMap;
        googleMap = ((SupportMapFragment)(getSupportFragmentManager().findFragmentById(R.id.map))).getMap();
        LatLng latLng = new LatLng(-33.796923, 150.922433);

        googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        googleMap.addMarker(new MarkerOptions()
                .position(latLng)
                .title("My Spot")
                .snippet("This is my spot!")
                .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));


        //  googleMap.getUiSettings().setCompassEnabled(true);
      //  googleMap.getUiSettings().setZoomControlsEnabled(true);
       // googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 10));

    }


}

Layout (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=".MainActivity" >

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

</RelativeLayout>

AndroidManifest.xml

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

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

        <permission
        android:name="com.example.googlev2map.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/>
<uses-permission android:name="com.example.googlev2map.permission.MAPS_RECEIVE"/>

<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"
        android:theme="@style/AppTheme" >
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyCkmUuFbR1ALKBk8ZdB1IXOQqEYfXaVcLs"/>
        <meta-data 
            android:name="com.google.android.gms.version" 
            android:value="@integer/google_play_services_version" /> 

        <activity
            android:name="com.example.googlev2map.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>

Logcat - UPDATED AFTER RECTIFYING GOOGLE PLAY SERVICES VERSION VALUE

            09-02 21:52:33.029: I/ApplicationPackageManager(10293): cscCountry is not German : H3G
09-02 21:52:33.779: W/dalvikvm(10293): VFY: unable to resolve direct method 74: Landroid/app/AlertDialog$Builder;.<init> (Landroid/content/Context;I)V
09-02 21:52:33.869: W/dalvikvm(10293): VFY: unable to resolve virtual method 23: Landroid/app/Activity;.getFragmentManager ()Landroid/app/FragmentManager;
09-02 21:52:33.879: W/dalvikvm(10293): VFY: unable to resolve instance field 42
09-02 21:52:33.879: W/dalvikvm(10293): VFY: unable to resolve static field 1323 (common_google_play_services_unsupported_date_text) in Lcom/google/android/gms/R$string;
09-02 21:52:33.879: W/dalvikvm(10293): VFY: unable to resolve static field 1319 (common_google_play_services_notification_needs_installation_title) in Lcom/google/android/gms/R$string;
09-02 21:52:33.879: W/dalvikvm(10293): VFY: unable to resolve static field 1320 (common_google_play_services_notification_needs_update_title) in Lcom/google/android/gms/R$string;
09-02 21:52:33.879: W/dalvikvm(10293): VFY: unable to resolve static field 1316 (common_google_play_services_needs_enabling_title) in Lcom/google/android/gms/R$string;
09-02 21:52:33.879: W/dalvikvm(10293): VFY: unable to resolve static field 1323 (common_google_play_services_unsupported_date_text) in Lcom/google/android/gms/R$string;
09-02 21:52:33.909: W/dalvikvm(10293): VFY: unable to resolve static field 1321 (common_google_play_services_notification_ticker) in Lcom/google/android/gms/R$string;
09-02 21:52:34.219: W/GooglePlayServicesUtil(10293): Google Play services out of date.  Requires 5089000 but found 3267110
09-02 21:52:34.279: W/GooglePlayServicesUtil(10293): Google Play services out of date.  Requires 5089000 but found 3267110
09-02 21:52:34.289: W/GooglePlayServicesUtil(10293): Google Play services out of date.  Requires 5089000 but found 3267110
09-02 21:52:34.319: W/GooglePlayServicesUtil(10293): Google Play services out of date.  Requires 5089000 but found 3267110
09-02 21:52:34.329: W/GooglePlayServicesUtil(10293): Google Play services out of date.  Requires 5089000 but found 3267110
09-02 21:52:34.339: W/GooglePlayServicesUtil(10293): Google Play services out of date.  Requires 5089000 but found 3267110
09-02 21:52:34.389: W/GooglePlayServicesUtil(10293): Google Play services out of date.  Requires 5089000 but found 3267110
09-02 21:52:34.479: W/GooglePlayServicesUtil(10293): Google Play services out of date.  Requires 5089000 but found 3267110
09-02 21:52:34.489: W/GooglePlayServicesUtil(10293): Google Play services out of date.  Requires 5089000 but found 3267110
09-02 21:52:34.649: W/GooglePlayServicesUtil(10293): Google Play services out of date.  Requires 5089000 but found 3267110
09-02 21:52:34.679: W/GooglePlayServicesUtil(10293): Google Play services out of date.  Requires 5089000 but found 3267110
09-02 21:52:34.709: W/dalvikvm(10293): threadid=1: thread exiting with uncaught exception (group=0x400207d8)
09-02 21:52:35.109: E/AndroidRuntime(10293): FATAL EXCEPTION: main
09-02 21:52:35.109: E/AndroidRuntime(10293): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.googlev2map/com.example.googlev2map.MainActivity}: java.lang.NullPointerException
09-02 21:52:35.109: E/AndroidRuntime(10293):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
09-02 21:52:35.109: E/AndroidRuntime(10293):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-02 21:52:35.109: E/AndroidRuntime(10293):    at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-02 21:52:35.109: E/AndroidRuntime(10293):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-02 21:52:35.109: E/AndroidRuntime(10293):    at android.os.Handler.dispatchMessage(Handler.java:99)
09-02 21:52:35.109: E/AndroidRuntime(10293):    at android.os.Looper.loop(Looper.java:123)
09-02 21:52:35.109: E/AndroidRuntime(10293):    at android.app.ActivityThread.main(ActivityThread.java:4627)
09-02 21:52:35.109: E/AndroidRuntime(10293):    at java.lang.reflect.Method.invokeNative(Native Method)
09-02 21:52:35.109: E/AndroidRuntime(10293):    at java.lang.reflect.Method.invoke(Method.java:521)
09-02 21:52:35.109: E/AndroidRuntime(10293):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
09-02 21:52:35.109: E/AndroidRuntime(10293):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
09-02 21:52:35.109: E/AndroidRuntime(10293):    at dalvik.system.NativeStart.main(Native Method)
09-02 21:52:35.109: E/AndroidRuntime(10293): Caused by: java.lang.NullPointerException
09-02 21:52:35.109: E/AndroidRuntime(10293):    at com.example.googlev2map.MainActivity.onCreate(MainActivity.java:27)
09-02 21:52:35.109: E/AndroidRuntime(10293):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-02 21:52:35.109: E/AndroidRuntime(10293):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-02 21:52:35.109: E/AndroidRuntime(10293):    ... 11 more
Community
  • 1
  • 1
Sameer
  • 71
  • 1
  • 1
  • 8

1 Answers1

2

Since you have a device that has 2.2 you cannot use any google play services version any higher than 3.2 (I believe that is where support for froyo stopped).

you are using the newest version of google play services which will not work with 2.2

You need to download and use Google Play Services for Froyo in the SDK Manager

tyczj
  • 71,600
  • 54
  • 194
  • 296
  • So that is why a Null pointer exception is coming? I mean anything else wrong with my code? – Sameer Sep 02 '14 at 14:56
  • probably yes that is the reason – tyczj Sep 02 '14 at 14:57
  • +10 for you. Thanks. So do i need to check my app on some other device higher than 2.2 as well as running a version of Google play services 5+???? – Sameer Sep 02 '14 at 15:00
  • 1
    well if you want to support 2.2 you can only use the froyo version in your app so I recommend dropping support for 2.2 since there is a very small percent that use it – tyczj Sep 02 '14 at 15:02
  • Sure and Yes i am going to drop it very soon. Thanks anyway. – Sameer Sep 02 '14 at 15:04
  • Well just to have a look as what happens, i imported and then added google play services lib for froyo. But lots of errors had come in the library itself as well as in my project. And the errors were like this value is already defined, this value is already defined etc. – Sameer Sep 02 '14 at 15:26
  • Yes that was my fault now no errors. but when i ran my app now using google play services for froyo, now i am getting some other errors in logcat like error inflating fragment, unable to start activity. I have updated my Logcat. Please have a look. – Sameer Sep 02 '14 at 15:36
  • ok now actually look at and read the error you just posted, it tells you the problem – tyczj Sep 02 '14 at 15:46
  • Ok so the meta data tag i have used in my app for the gms version has got the wrong value. Should i need to write 5089000 there as value or what? – Sameer Sep 02 '14 at 15:49
  • you literally need to just copy and paste what it says in your manifest thats it – tyczj Sep 02 '14 at 15:52
  • ok now when i added this statement, and ran my app, i have got following errors, look at my logcat once again kindly. – Sameer Sep 02 '14 at 15:57
  • why are you not copying and pasting what is in the error like I said – tyczj Sep 02 '14 at 16:00
  • ok now when i have pasted what was mentioned in my manifest like: then now it gets underlined in red and says, error: Error: No resource found that matches the given name (at 'value' with value '@integer/google_play_services_version'). – Sameer Sep 02 '14 at 16:03
  • ok i got it, there would be true in the value tag. Let me run and check. – Sameer Sep 02 '14 at 16:05
  • Just for the last time look at my logcat i have updated now kindly. – Sameer Sep 02 '14 at 16:07
  • Where can i find the value as what i have read about gms version value is that its an integer and would be found inside res folder in values.xml but i can't see there because i haven't declared it so how to find it? like said in the link http://stackoverflow.com/questions/22562215/android-google-map-v2-stopped – Sameer Sep 02 '14 at 16:23
  • Kindly have a look at my logcat errors for the last time and tell me now what to do? – Sameer Sep 02 '14 at 16:59
  • Finally i have successfully got a screen without being crashed. saying that google play services needs to be updated and below that line there is button to update Google play services as well. As far as NPE is concerned, so i was getting that error because as there is no map being loaded so how can Lattitude and Longitude be pointed. Thanks tycjz. – Sameer Sep 03 '14 at 13:29