Android 4.2.2上的google Map v2出现致命错误
我在Android 4.1和4.3上遇到以下致命错误,代码工作正常:Android 4.2.2上的google Map v2出现致命错误,android,google-maps,Android,Google Maps,我在Android 4.1和4.3上遇到以下致命错误,代码工作正常: 11-10 20:53:21.425 8940-8957/ganbi_collector.com.ganbi_collector E/NativeCrypto﹕ ssl=0x5ca3abe0 cert_verify_callback x509_store_ctx=0x5ee64ab0 arg=0x0 11-10 20:53:21.425 8940-8957/ganbi_collector.com.ganbi_col
11-10 20:53:21.425 8940-8957/ganbi_collector.com.ganbi_collector E/NativeCrypto﹕ ssl=0x5ca3abe0 cert_verify_callback x509_store_ctx=0x5ee64ab0 arg=0x0
11-10 20:53:21.425 8940-8957/ganbi_collector.com.ganbi_collector E/NativeCrypto﹕ ssl=0x5ca3abe0 cert_verify_callback calling verifyCertificateChain authMethod=ECDHE_ECDSA
11-10 20:53:21.502 8940-8940/ganbi_collector.com.ganbi_collector E/linker﹕ load_library(linker.cpp:759): library "libmaliinstr.so" not found
11-10 20:53:21.971 8940-8940/ganbi_collector.com.ganbi_collector E/SpannableStringBuilder﹕ SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
11-10 20:53:21.972 8940-8940/ganbi_collector.com.ganbi_collector E/SpannableStringBuilder﹕ SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
11-10 20:53:22.034 8940-8940/ganbi_collector.com.ganbi_collector E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
at ganbi_collector.com.ganbi_collector.MainActivity.setUpMapIfNeeded(MainActivity.java:125)
at ganbi_collector.com.ganbi_collector.MainActivity.onLocationChanged(MainActivity.java:311)
at com.google.android.gms.internal.lx$a.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5434)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:834)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
以下是目标活动的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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/fragment_container">
<fragment
android:id="@+id/ganbi_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
</FrameLayout>
我正在使用带有android 4.2.2的阿尔卡特pop9进行调试,代码在带有安卓4.1的HTC desire 500上运行良好,同样的代码在阿尔卡特Idol x2上运行,没有任何问题。@zgc7009用他神奇的话告诉了我解决方案的关键:这是一个种族案例,描述了在通货膨胀之前获取地图的尝试。我把地图从这场比赛中移开,只有在以后安全的情况下才能打这个电话
我对它为什么与其他设备协同工作有不同的解释:实际上,这是Android开发中的主要挑战之一,不同的硬件具有不同的响应时间。阿尔卡特pop9似乎有更好的GPS连接时间。我正在初始化“地图接通GPS”连接,这在其他测试手机上是正常的,因为GPS为充气机提供了足够的工作时间。需要设置地图中的第125行是什么?是gMap=MapFragment getFragmentManager.findFragmentByIdR.id.ganbi_map.getMap;因为如果是这样的话,我将假设findFragmentById返回null。是的,这是您提到的行,但是什么可能会导致一个版本出现这种情况,并导致另一个版本出现相同的错误?!为了调试,我在代码中添加了以下行:Fragment x=getFragmentManager.findffragmentbyidr.id.ganbi_-map;它不会生成任何错误,现在错误移动到第127行,与您上面提到的同一行相同。因此,很明显,错误是由getMap生成的,而不是由FindFragmentById生成的。您正在尝试在地图实际膨胀之前获取它。尝试将代码移动到onResume而不是onCreate,这样您就知道视图已正确膨胀。它以前是工作的,但是你很幸运,因为它是一个竞赛案例。只要对你输入的调试代码进行注释,它就可以找到片段,因为片段实际上在那里,但是它膨胀的映射还没有,所以getMap会给你错误。
private GoogleMap gMap;
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (gMap == null) {
gMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.ganbi_map)).getMap();
// Check if we were successful in obtaining the map.
if (gMap != null) {
// The Map is verified. It is now safe to manipulate the map.
// Load map preferences
Log.d("Info", "Map ready for initialization");
gMap.setMyLocationEnabled(true);
LogMe(Boolean.toString(locationTrack));
}
}
}
public void onLocationChanged(Location loc) {
// Marks marks = new Marks();
String msg = "Location change received: " +
Double.toString(loc.getLatitude()) + "," +
Double.toString(loc.getLongitude());
LogMe(msg);
lastLoc = new LatLng(loc.getLatitude(),loc.getLongitude());
// Move the camera instantly to current location with a zoom of 15.
if (gMap == null){
setUpMapIfNeeded();
} else {
gMap.moveCamera(CameraUpdateFactory.newLatLngZoom(lastLoc, 15));
// marks.getNearMarks(lastLoc);
getNearMarks(lastLoc);
}
}