问题描述
我开发一个简单的应用程序来显示地图。对于这个我是一个真正的设备上测试应用程序为:三星Galaxy欧罗巴(Android 2.2的)。不幸的是我的应用程序被关闭/在logcat中(我提伴随着我的code)正在查看大量的错误forcely坠毁。我已经包括 google_play_services_lib 按照规则,但在徒劳的。是的,我已经触及了每一个位的解决方案这里提到这样的:
不过,在应用这些出这么多其他的解决办法并没有如期实现。而我的应用程序仍然会崩溃。 我甚至测试的在线仿真器Manymo我的应用程序,但我的应用程序崩溃有作为的模拟器。 只是我的谷歌播放服务的版本,是不是让我的应用程序运行还是别的什么原因?我打算把我的code和所有其他位,所以你们可以看看到挖掘出的根本原因。
MainActivity.java
包com.example.googlev2map;进口com.google.android.gms.maps.CameraUpdateFactory;
进口com.google.android.gms.maps.GoogleMap;
进口com.google.android.gms.maps.SupportMapFragment;
进口com.google.android.gms.maps.model.BitmapDescriptorFactory;
进口com.google.android.gms.maps.model.LatLng;
进口com.google.android.gms.maps.model.MarkerOptions;
进口android.os.Bundle;
进口android.app.Activity;
进口android.support.v4.app.FragmentActivity;
进口android.view.Menu;公共类MainActivity扩展FragmentActivity { @覆盖
保护无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_main);
GoogleMap的GoogleMap的;
使用GoogleMap =((SupportMapFragment)(getSupportFragmentManager()findFragmentById(R.id.map))。)的GetMap();
经纬度的latLng =新的经纬度(-33.796923,150.922433); googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
googleMap.addMarker(新的MarkerOptions()
.POSITION(的latLng)
.title伪(我的位置)
是.snippet(这是我的位置!)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
// googleMap.getUiSettings()setCompassEnabled(真)。
// googleMap.getUiSettings()setZoomControlsEnabled(真)。
// googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(的latLng,10)); }
}
布局(activity_main.xml中)
<的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:paddingBottom会=@扪/ activity_vertical_margin
机器人:paddingLeft =@扪/ activity_horizontal_margin
机器人:paddingRight =@扪/ activity_horizontal_margin
机器人:paddingTop =@扪/ activity_vertical_margin
工具:上下文=MainActivity。><片段
机器人:ID =@ + ID /图
机器人:layout_width =match_parent
机器人:layout_height =match_parent
类=com.google.android.gms.maps.SupportMapFragment/>< / RelativeLayout的>
的AndroidManifest.xml
<?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.example.googlev2map
安卓版code =1
机器人:=的versionName1.0> <用途-SDK
安卓的minSdkVersion =8
机器人:targetSdkVersion =20/> <许可
机器人:名字=com.example.googlev2map.permission.MAPS_RECEIVE
安卓的ProtectionLevel =签名/>
<使用许可权的android:NAME =com.example.googlev2map.permission.MAPS_RECEIVE/><使用许可权的android:NAME =android.permission.INTERNET对/>
<使用许可权的android:NAME =android.permission.ACCESS_NETWORK_STATE/>
<使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAGE/>
<使用许可权的android:NAME =com.google.android.providers.gsf.permission.READ_GSERVICES/>
<! - 不需要下面的两个权限使用
谷歌地图Android版API V2,但建议。 - >
<使用许可权的android:NAME =android.permission.ACCESS_COARSE_LOCATION/>
<使用许可权的android:NAME =android.permission.ACCESS_FINE_LOCATION/><用途特征
机器人:glEsVersion =0x00020000
机器人:要求=真/> <应用
机器人:allowBackup =真
机器人:图标=@绘制/ ic_launcher
机器人:标签=@字符串/ APP_NAME
机器人:主题=@风格/ AppTheme>
&所述;元数据
机器人:名字=com.google.android.maps.v2.API_KEY
机器人:值=AIzaSyCkmUuFbR1ALKBk8ZdB1IXOQqEYfXaVcLs/>
&所述;元数据
机器人:名字=com.google.android.gms.version
机器人:值=@整数/ GOOGLE_PLAY_SERVICES_VERSION/> <活动
机器人:名字=com.example.googlev2map.MainActivity
机器人:标签=@字符串/ APP_NAME>
&所述;意图滤光器>
<作用机器人:名字=android.intent.action.MAIN/> <类机器人:名字=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT; < /用途>< /清单>
的logcat - 更新后,纠偏Google Play服务版本值
09-02 21:52:33.029:I / ApplicationPackageManager(10293):cscCountry是不是德国:H3G
09-02 21:52:33.779:W / dalvikvm(10293):VFY:无法解决直接的方法74:Landroid /应用/ AlertDialog $生成器;<&初始化GT; (Landroid /内容/上下文;我)V
09-02 21:52:33.869:W / dalvikvm(10293):VFY:无法解析虚方法23:Landroid /应用/活动; .getFragmentManager()Landroid /应用/ FragmentManager;
09-02 21:52:33.879:W / dalvikvm(10293):VFY:无法解析实例字段42
09-02 21:52:33.879:W / dalvikvm(10293):VFY:无法解析静态字段1323(common_google_play_services_unsupported_date_text)在LCOM /谷歌/安卓/ GMS / R $串;
09-02 21:52:33.879:W / dalvikvm(10293):VFY:无法解析静态字段1319(common_google_play_services_notification_needs_installation_title)在LCOM /谷歌/安卓/ GMS / R $串;
09-02 21:52:33.879:W / dalvikvm(10293):VFY:无法解析静态字段1320(common_google_play_services_notification_needs_update_title)在LCOM /谷歌/安卓/ GMS / R $串;
09-02 21:52:33.879:W / dalvikvm(10293):VFY:无法解析静态字段1316(common_google_play_services_needs_enabling_title)在LCOM /谷歌/安卓/ GMS / R $串;
09-02 21:52:33.879:W / dalvikvm(10293):VFY:无法解析静态字段1323(common_google_play_services_unsupported_date_text)在LCOM /谷歌/安卓/ GMS / R $串;
09-02 21:52:33.909:W / dalvikvm(10293):VFY:无法解析静态字段1321(common_google_play_services_notification_ticker)在LCOM /谷歌/安卓/ GMS / R $串;
09-02 21:52:34.219:W / GooglePlayServicesUtil(10293):谷歌Play服务的过时。需要5089000但发现3267110
09-02 21:52:34.279:W / GooglePlayServicesUtil(10293):谷歌Play服务的过时。需要5089000但发现3267110
09-02 21:52:34.289:W / GooglePlayServicesUtil(10293):谷歌Play服务的过时。需要5089000但发现3267110
09-02 21:52:34.319:W / GooglePlayServicesUtil(10293):谷歌Play服务的过时。需要5089000但发现3267110
09-02 21:52:34.329:W / GooglePlayServicesUtil(10293):谷歌Play服务的过时。需要5089000但发现3267110
09-02 21:52:34.339:W / GooglePlayServicesUtil(10293):谷歌Play服务的过时。需要5089000但发现3267110
09-02 21:52:34.389:W / GooglePlayServicesUtil(10293):谷歌Play服务的过时。需要5089000但发现3267110
09-02 21:52:34.479:W / GooglePlayServicesUtil(10293):谷歌Play服务的过时。需要5089000但发现3267110
09-02 21:52:34.489:W / GooglePlayServicesUtil(10293):谷歌Play服务的过时。需要5089000但发现3267110
09-02 21:52:34.649:W / GooglePlayServicesUtil(10293):谷歌Play服务的过时。需要5089000但发现3267110
09-02 21:52:34.679:W / GooglePlayServicesUtil(10293):谷歌Play服务的过时。需要5089000但发现3267110
09-02 21:52:34.709:W / dalvikvm(10293):主题ID = 1:螺纹未捕获的异常(组= 0x400207d8)退出
09-02 21:52:35.109:E / AndroidRuntime(10293):致命异常:主要
09-02 21:52:35.109:E / AndroidRuntime(10293):了java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.googlev2map / com.example.googlev2map.MainActivity}:显示java.lang.NullPointerException
09-02 21:52:35.109:E / AndroidRuntime(10293):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
09-02 21:52:35.109:E / AndroidRuntime(10293):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-02 21:52:35.109:E / AndroidRuntime(10293):在android.app.ActivityThread.access $ 2300(ActivityThread.java:125)
09-02 21:52:35.109:E / AndroidRuntime(10293):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:2033)
09-02 21:52:35.109:E / AndroidRuntime(10293):在android.os.Handler.dispatchMessage(Handler.java:99)
09-02 21:52:35.109:E / AndroidRuntime(10293):在android.os.Looper.loop(Looper.java:123)
09-02 21:52:35.109:E / AndroidRuntime(10293):在android.app.ActivityThread.main(ActivityThread.java:4627)
09-02 21:52:35.109:E / AndroidRuntime(10293):在java.lang.reflect.Method.invokeNative(本机方法)
09-02 21:52:35.109:E / AndroidRuntime(10293):在java.lang.reflect.Method.invoke(Method.java:521)
09-02 21:52:35.109:E / AndroidRuntime(10293):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:858)
09-02 21:52:35.109:E / AndroidRuntime(10293):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
09-02 21:52:35.109:E / AndroidRuntime(10293):在dalvik.system.NativeStart.main(本机方法)
09-02 21:52:35.109:E / AndroidRuntime(10293):致:显示java.lang.NullPointerException
09-02 21:52:35.109:E / AndroidRuntime(10293):在com.example.googlev2map.MainActivity.onCreate(MainActivity.java:27)
09-02 21:52:35.109:E / AndroidRuntime(10293):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-02 21:52:35.109:E / AndroidRuntime(10293):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-02 21:52:35.109:E / AndroidRuntime(10293):... 11个
既然您具有2.2的设备不能使用任何谷歌播放服务的版本比任何更高的 3.2
(我相信这是对的地方支持Froyo的停止)。
您使用的是谷歌最新版本的播放,不会与2.2工作服务
您需要下载并使用谷歌播放服务的Froyo
在SDK管理器
I am developing a simple application to show a map. For this i am testing my application on a real device as: Samsung Galaxy Europa (Android 2.2). Unfortunately my application is being closed/crashed forcely with lots of errors being viewed in logcat (i am mentioning along with my code). I have included google_play_services_lib as per the rules but in-vain. And Yes i have scratched every bit of solutions mentioned here like:
- Solution 1 - Google play services out of date
- Solution 2 - Google play services out of date
- Solution 3 - Google play services out of date
- Solution 4 - Google play services out of date
- Solution 5 - Google play services out of date
- Solution 6 - Google play services out of date
- Solution 7 - Null pointer exception calling fragment
But applying these out of so many other solution didn't come to fruition. And my application is still crashing. I have even tested my application on online Manymo emulator but my application is crashing there as well on emulator. Is only my google play services version a cause that is not letting my app to run or something else? I am going to put my code and every other bit so you guys can have a look to dig-out the root cause.
MainActivity.java
package com.example.googlev2map;
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.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import android.os.Bundle;
import android.app.Activity;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GoogleMap googleMap;
googleMap = ((SupportMapFragment)(getSupportFragmentManager().findFragmentById(R.id.map))).getMap();
LatLng latLng = new LatLng(-33.796923, 150.922433);
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
googleMap.addMarker(new MarkerOptions()
.position(latLng)
.title("My Spot")
.snippet("This is my spot!")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
// googleMap.getUiSettings().setCompassEnabled(true);
// googleMap.getUiSettings().setZoomControlsEnabled(true);
// googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 10));
}
}
Layout (activity_main.xml)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.googlev2map"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="20" />
<permission
android:name="com.example.googlev2map.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.googlev2map.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- The following two permissions are not required to use
Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyCkmUuFbR1ALKBk8ZdB1IXOQqEYfXaVcLs"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name="com.example.googlev2map.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Logcat - UPDATED AFTER RECTIFYING GOOGLE PLAY SERVICES VERSION VALUE
09-02 21:52:33.029: I/ApplicationPackageManager(10293): cscCountry is not German : H3G
09-02 21:52:33.779: W/dalvikvm(10293): VFY: unable to resolve direct method 74: Landroid/app/AlertDialog$Builder;.<init> (Landroid/content/Context;I)V
09-02 21:52:33.869: W/dalvikvm(10293): VFY: unable to resolve virtual method 23: Landroid/app/Activity;.getFragmentManager ()Landroid/app/FragmentManager;
09-02 21:52:33.879: W/dalvikvm(10293): VFY: unable to resolve instance field 42
09-02 21:52:33.879: W/dalvikvm(10293): VFY: unable to resolve static field 1323 (common_google_play_services_unsupported_date_text) in Lcom/google/android/gms/R$string;
09-02 21:52:33.879: W/dalvikvm(10293): VFY: unable to resolve static field 1319 (common_google_play_services_notification_needs_installation_title) in Lcom/google/android/gms/R$string;
09-02 21:52:33.879: W/dalvikvm(10293): VFY: unable to resolve static field 1320 (common_google_play_services_notification_needs_update_title) in Lcom/google/android/gms/R$string;
09-02 21:52:33.879: W/dalvikvm(10293): VFY: unable to resolve static field 1316 (common_google_play_services_needs_enabling_title) in Lcom/google/android/gms/R$string;
09-02 21:52:33.879: W/dalvikvm(10293): VFY: unable to resolve static field 1323 (common_google_play_services_unsupported_date_text) in Lcom/google/android/gms/R$string;
09-02 21:52:33.909: W/dalvikvm(10293): VFY: unable to resolve static field 1321 (common_google_play_services_notification_ticker) in Lcom/google/android/gms/R$string;
09-02 21:52:34.219: W/GooglePlayServicesUtil(10293): Google Play services out of date. Requires 5089000 but found 3267110
09-02 21:52:34.279: W/GooglePlayServicesUtil(10293): Google Play services out of date. Requires 5089000 but found 3267110
09-02 21:52:34.289: W/GooglePlayServicesUtil(10293): Google Play services out of date. Requires 5089000 but found 3267110
09-02 21:52:34.319: W/GooglePlayServicesUtil(10293): Google Play services out of date. Requires 5089000 but found 3267110
09-02 21:52:34.329: W/GooglePlayServicesUtil(10293): Google Play services out of date. Requires 5089000 but found 3267110
09-02 21:52:34.339: W/GooglePlayServicesUtil(10293): Google Play services out of date. Requires 5089000 but found 3267110
09-02 21:52:34.389: W/GooglePlayServicesUtil(10293): Google Play services out of date. Requires 5089000 but found 3267110
09-02 21:52:34.479: W/GooglePlayServicesUtil(10293): Google Play services out of date. Requires 5089000 but found 3267110
09-02 21:52:34.489: W/GooglePlayServicesUtil(10293): Google Play services out of date. Requires 5089000 but found 3267110
09-02 21:52:34.649: W/GooglePlayServicesUtil(10293): Google Play services out of date. Requires 5089000 but found 3267110
09-02 21:52:34.679: W/GooglePlayServicesUtil(10293): Google Play services out of date. Requires 5089000 but found 3267110
09-02 21:52:34.709: W/dalvikvm(10293): threadid=1: thread exiting with uncaught exception (group=0x400207d8)
09-02 21:52:35.109: E/AndroidRuntime(10293): FATAL EXCEPTION: main
09-02 21:52:35.109: E/AndroidRuntime(10293): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.googlev2map/com.example.googlev2map.MainActivity}: java.lang.NullPointerException
09-02 21:52:35.109: E/AndroidRuntime(10293): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
09-02 21:52:35.109: E/AndroidRuntime(10293): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-02 21:52:35.109: E/AndroidRuntime(10293): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-02 21:52:35.109: E/AndroidRuntime(10293): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-02 21:52:35.109: E/AndroidRuntime(10293): at android.os.Handler.dispatchMessage(Handler.java:99)
09-02 21:52:35.109: E/AndroidRuntime(10293): at android.os.Looper.loop(Looper.java:123)
09-02 21:52:35.109: E/AndroidRuntime(10293): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-02 21:52:35.109: E/AndroidRuntime(10293): at java.lang.reflect.Method.invokeNative(Native Method)
09-02 21:52:35.109: E/AndroidRuntime(10293): at java.lang.reflect.Method.invoke(Method.java:521)
09-02 21:52:35.109: E/AndroidRuntime(10293): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
09-02 21:52:35.109: E/AndroidRuntime(10293): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
09-02 21:52:35.109: E/AndroidRuntime(10293): at dalvik.system.NativeStart.main(Native Method)
09-02 21:52:35.109: E/AndroidRuntime(10293): Caused by: java.lang.NullPointerException
09-02 21:52:35.109: E/AndroidRuntime(10293): at com.example.googlev2map.MainActivity.onCreate(MainActivity.java:27)
09-02 21:52:35.109: E/AndroidRuntime(10293): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-02 21:52:35.109: E/AndroidRuntime(10293): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-02 21:52:35.109: E/AndroidRuntime(10293): ... 11 more
Since you have a device that has 2.2 you cannot use any google play services version any higher than 3.2
(I believe that is where support for froyo stopped).
you are using the newest version of google play services which will not work with 2.2
You need to download and use Google Play Services for Froyo
in the SDK Manager
这篇关于谷歌是否发挥服务版本正在过时不能让应用程序运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!