2014-02-09 24 views
0

我正在嘗試構建谷歌地圖應用程序....我的操作與https://developers.google.com/maps/documentation/android/(hello地圖)中顯示的相同。但是當我運行應用程序時,它崩潰了。我不知道是什麼導致了這個問題。我的代碼是: package com.googlemaps;Android地圖基本應用程序崩潰

import java.io.IOException; 

import com.google.android.gms.maps.CameraUpdateFactory; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.MapFragment; 
import com.google.android.gms.maps.SupportMapFragment; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.MarkerOptions; 

public class MainActivity extends Activity { 

private GoogleMap maps; 

final static String URL = "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/"; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    // Get a handle to the Map Fragment 
    maps = ((MapFragment) getFragmentManager() .findFragmentById(R.id.map)).getMap(); 
    maps.setMapType(GoogleMap.MAP_TYPE_SATELLITE); 
    LatLng as = new LatLng(141.0819,37.092); 
    maps.setMyLocationEnabled(true); 
    maps.moveCamera(CameraUpdateFactory.newLatLngZoom(as, 13)); 
    maps.addMarker(new MarkerOptions().title("PlaceName").snippet("Magnitude").position(as)); 


    } 

XML ::

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 

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

</LinearLayout> 

的logcat:

02-09 06:46:04.940: W/GooglePlayServicesUtil(1308): Google Play services out of date. Requires 4132500 but found 4033530 
02-09 06:46:04.960: W/GooglePlayServicesUtil(1308): Google Play services out of date. Requires 4132500 but found 4033530 
02-09 06:46:04.970: W/GooglePlayServicesUtil(1308): Google Play services out of date. Requires 4132500 but found 4033530 
02-09 06:46:05.050: W/GooglePlayServicesUtil(1308): Google Play services out of date. Requires 4132500 but found 4033530 
02-09 06:46:05.120: W/GooglePlayServicesUtil(1308): Google Play services out of date. Requires 4132500 but found 4033530 
02-09 06:46:05.210: W/GooglePlayServicesUtil(1308): Google Play services out of date. Requires 4132500 but found 4033530 
02-09 06:46:05.210: D/AndroidRuntime(1308): Shutting down VM 
02-09 06:46:05.210: W/dalvikvm(1308): threadid=1: thread exiting with uncaught exception (group=0xb4aceba8) 
02-09 06:46:05.240: E/AndroidRuntime(1308): FATAL EXCEPTION: main 
02-09 06:46:05.240: E/AndroidRuntime(1308): Process: com.googlemaps, PID: 1308 
02-09 06:46:05.240: E/AndroidRuntime(1308): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.googlemaps/com.googlemaps.MainActivity}: java.lang.NullPointerException 
02-09 06:46:05.240: E/AndroidRuntime(1308):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195) 
02-09 06:46:05.240: E/AndroidRuntime(1308):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
02-09 06:46:05.240: E/AndroidRuntime(1308):  at android.app.ActivityThread.access$800(ActivityThread.java:135) 
02-09 06:46:05.240: E/AndroidRuntime(1308):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
02-09 06:46:05.240: E/AndroidRuntime(1308):  at android.os.Handler.dispatchMessage(Handler.java:102) 
02-09 06:46:05.240: E/AndroidRuntime(1308):  at android.os.Looper.loop(Looper.java:136) 
02-09 06:46:05.240: E/AndroidRuntime(1308):  at android.app.ActivityThread.main(ActivityThread.java:5017) 
02-09 06:46:05.240: E/AndroidRuntime(1308):  at java.lang.reflect.Method.invokeNative(Native Method) 
02-09 06:46:05.240: E/AndroidRuntime(1308):  at java.lang.reflect.Method.invoke(Method.java:515) 
02-09 06:46:05.240: E/AndroidRuntime(1308):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 
02-09 06:46:05.240: E/AndroidRuntime(1308):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
02-09 06:46:05.240: E/AndroidRuntime(1308):  at dalvik.system.NativeStart.main(Native Method) 
02-09 06:46:05.240: E/AndroidRuntime(1308): Caused by: java.lang.NullPointerException 
02-09 06:46:05.240: E/AndroidRuntime(1308):  at com.googlemaps.MainActivity.onCreate(MainActivity.java:52) 
02-09 06:46:05.240: E/AndroidRuntime(1308):  at android.app.Activity.performCreate(Activity.java:5231) 
02-09 06:46:05.240: E/AndroidRuntime(1308):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
02-09 06:46:05.240: E/AndroidRuntime(1308):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) 
02-09 06:46:05.240: E/AndroidRuntime(1308):  ... 11 more 
02-09 06:47:02.900: I/Process(1308): Sending signal. PID: 1308 SIG: 9 

我覺得問題在一些線路:

 maps.setMapType(GoogleMap.MAP_TYPE_SATELLITE); 
    LatLng as = new LatLng(141.0819,37.092); 
    maps.setMyLocationEnabled(true); 
    maps.moveCamera(CameraUpdateFactory.newLatLngZoom(as, 13)); 
    maps.addMarker(new MarkerOptions().title("PlaceName").snippet("Magnitude").position(as)); 

應用程序加載地圖剛罰款如果所有這些代碼被刪除..但皮疹我f不是。

回答

0

您是否擁有最新版本的Google服務? setMapType()是否會引發問題?它在oncreate的第52行說空指針。那是什麼?

+0

setMapType()不是應用程序。應用程序仍然崩潰,如果它被刪除 –

+0

我不太瞭解編程>>>請幫我...什麼是空指針? –