Question

I am working on fragments to show a google map . But i keep gettin crashes from the app when showing the map. I already have the android-support-v4 and google-play-services in the libs. This is the code for my activity :

package com.example.attijaribank2; 
import android.app.Activity;
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.SupportMapFragment;
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 Votresolde 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.activity_solde);
map =         ((SupportMapFragment)getSupportFragmentManager().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)));


    map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));


    map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));


    map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);    
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_solde, menu);
return true;
}

}

what am I doing wrong ? or is it about the xml file ?

This is the xml file :

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

and logcat :

03-02 17:38:38.195: D/dalvikvm(372): DexOpt: couldn't find field     
Landroid/content/res/Configuration;.smallestScreenWidthDp
03-02 17:38:38.195: W/dalvikvm(372): VFY: unable to resolve instance field 23
03-02 17:38:38.195: D/dalvikvm(372): VFY: replacing opcode 0x52 at 0x0012
03-02 17:38:38.195: D/dalvikvm(372): VFY: dead code 0x0014-0018 in   
Lcom/google/android/gms/common/GooglePlayServicesUtil;.b   
(Landroid/content/res/Resources;)Z

W/GooglePlayServicesUtil(372): Google Play services is missing.
W/GooglePlayServicesUtil(372): Google Play services is missing.
03-02 17:38:38.295: D/AndroidRuntime(372): Shutting down VM
03-02 17:38:38.295: W/dalvikvm(372): threadid=1: thread exiting with uncaught exception   
(group=0x40015560)
03-02 17:38:38.305: E/AndroidRuntime(372): FATAL EXCEPTION: main
E/AndroidRuntime(372): java.lang.RuntimeException: Unable to start activity  
ComponentInfo{com.example.attijaribank2/com.example.attijaribank2.Votresolde}:   
java.lang.NullPointerException
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:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.attijaribank2.Votresolde.onCreate(Votresolde.java:26)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)

It says ths google play services is missing yet I did Import it .

Was it helpful?

Solution

Google Play services is missing.

this means that either you are testing on emulator on which Google play is not installed

Please check the official link to clarify your doubt which says:

Note: Google Play services is not supported on the Android emulator — to develop using the APIs, you need to provide a development device such as an Android phone or tablet. 

http://developer.android.com/google/play-services/setup.html

OTHER TIPS

I found this answer, that solved my issue: https://stackoverflow.com/a/13719616/1827048

.

Especially this part was useful to me:

a)copy directory ANDROID_SDK_DIR/extras/google/google_play_services/libproject/google-play-services_lib to root of your project

b)add next line to the YOUR_PROJECT/project.properties:

android.library.reference.1=google-play-services_lib

c)add next lines to the YOUR_PROJECT/proguard-project.txt:

keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
}

Note: If you create application with min SDK = 8, please use android support library v4 + SupportMapFragment instead of MapFragment.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top