谷歌地图API V2:应用程序崩溃时我想查看地图 [英] Google maps api v2 : the application crashes when I want to view the map
问题描述
我的工作片段显示谷歌地图。但我一直从应用程序崩溃开始报显示地图时。
我已经有Android的支持-v4和在库的Google Play服务。
这是code代表我的活动:
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;
}
}
我是什么做错了吗?或者是有关XML文件?
what am I doing wrong ? or is it about the xml file ?
这是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)
报告说,谷歌部份播放服务缺失但我没有导入。
It says ths google play services is missing yet I did Import it .
推荐答案
谷歌Play服务的缺失。
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
这篇关于谷歌地图API V2:应用程序崩溃时我想查看地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!