为什么google maps api v2无法在api 8及更低版本上运行?

时间:2014-05-18 21:26:50

标签: android api google-maps

我使用谷歌播放服务中的谷歌地图api v2 开发应用程序,我的工作正常。但是当我尝试运行我的应用程序时在api level 8设备上。(xperia arc / old device)它没有被加载和崩溃。 但是在更高的api设备上,它的工作正常(例如:s4,note3,s5)。

我得到有关我的位置的信息:

    LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

    Criteria criteria = new Criteria();
    String provider = locationManager.getBestProvider(criteria, true);
    Location location = locationManager.getLastKnownLocation(provider);
    double latitude = location.getLatitude();
    double longitude = location.getLongitude();

    //Get location info
    Geocoder gc = new Geocoder(this);
    List<Address> list = gc.getFromLocation(latitude, longitude, 1);
    String country = list.get(0).getCountryName();
    String city = list.get(0).getLocality();
    String street = list.get(0).getAddressLine(0);

    Toast.makeText(MainActivity.this,"country: "+country+"\nCity: "+city+"\nAddress: "+street, 2000).show();

logcat错误:

05-19 00:17:11.876: E/AndroidRuntime(2201): FATAL EXCEPTION: main
05-19 00:17:11.876: E/AndroidRuntime(2201): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bis.work/com.bis.work.MainActivity}: java.lang.NullPointerException
05-19 00:17:11.876: E/AndroidRuntime(2201):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
05-19 00:17:11.876: E/AndroidRuntime(2201):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
05-19 00:17:11.876: E/AndroidRuntime(2201):     at android.app.ActivityThread.access$1500(ActivityThread.java:121)
05-19 00:17:11.876: E/AndroidRuntime(2201):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
05-19 00:17:11.876: E/AndroidRuntime(2201):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-19 00:17:11.876: E/AndroidRuntime(2201):     at android.os.Looper.loop(Looper.java:130)
05-19 00:17:11.876: E/AndroidRuntime(2201):     at android.app.ActivityThread.main(ActivityThread.java:3701)
05-19 00:17:11.876: E/AndroidRuntime(2201):     at java.lang.reflect.Method.invokeNative(Native Method)
05-19 00:17:11.876: E/AndroidRuntime(2201):     at java.lang.reflect.Method.invoke(Method.java:507)
05-19 00:17:11.876: E/AndroidRuntime(2201):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
05-19 00:17:11.876: E/AndroidRuntime(2201):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
05-19 00:17:11.876: E/AndroidRuntime(2201):     at dalvik.system.NativeStart.main(Native Method)
05-19 00:17:11.876: E/AndroidRuntime(2201): Caused by: java.lang.NullPointerException
05-19 00:17:11.876: E/AndroidRuntime(2201):     at com.bibas.workclock.MainActivity.map(MainActivity.java:1890)
05-19 00:17:11.876: E/AndroidRuntime(2201):     at com.bibas.workclock.MainActivity.onCreate(MainActivity.java:150)
05-19 00:17:11.876: E/AndroidRuntime(2201):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-19 00:17:11.876: E/AndroidRuntime(2201):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
05-19 00:17:11.876: E/AndroidRuntime(2201):     ... 11 more

我该如何解决? 谢谢:)

1 个答案:

答案 0 :(得分:1)

如果您需要支持旧版本,则需要使用现在与Google Play Services for Froyo分开的Google Play Services。仍然Google Play Services for Froyo也适用于较新版本,因此您不需要2个单独的应用程序版本。

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

  

注意:Google Play服务4.0。30(2013年11月发布)和更新版本   版本需要Android 2.3或更高版本。如果您的应用支持Android   2.2,您可以继续使用Google Play服务SDK进行开发,但必须从SDK安装Froyo的Google Play服务   管理器。