我遇到以下致命错误,代码在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_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>
以下是造成错误的方法:
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);
}
}
我正在使用Alcatel pop9和andorid 4.2.2进行调试,代码在使用Android 4.1的HTC欲望500上运行完全,并且相同的代码与Alcatel Idol x2一起使用没有任何问题。
答案 0 :(得分:0)
@ zgc7009用他神奇的词语给出了解决方案的关键:这是一个描述在通货膨胀之前获得地图的试验案例。我试图让地图远离这场比赛,只是让这个电话在以后发生安全。
我对其与其他设备合作的原因有不同的解释:实际上这是Android开发中的主要挑战之一,其中不同的硬件具有不同的响应时间。似乎阿尔卡特pop9具有更好的GPS连接时间。我正在初始化地图获得GPS连接,这在其他测试手机上是可以的,其中GPS有足够的时间让inflater工作。