私はグーグルマップを表示するためにフラグメントに取り組んでいます。しかし、私は地図を表示するときにアプリからgettinがクラッシュし続けます。私はすでにライブラリにandroid-support-v4とgoogle-play-servicesを持っています。これは私の活動のコードです:
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;
}
}
私は何を間違っているのですか?それともxmlファイルについてですか?
これはxmlファイルです:
<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"/>
と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)
それは、グーグルプレイサービスが欠落していると言っていますが、私はそれをインポートしました。