我在片段中使用谷歌地图。它运作良好,一切都很好。 但是当我离开地图片段时,它变得非常奇怪!
我也在使用json.io lib来解析来自/到服务器的JSON。关闭地图片段后,我从json.io获得以下错误:
java.io.IOException: Class listed in @type [com.myapp.constructors.GeoConstructor] is not found, pos = 43
应用程序正常工作,直到我打开和关闭地图片段。如果我将maps.MapFragment调用插入任何其他Activity / Fragment,也会发生奇怪的错误!
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
因此错误必须是Fragment的调用。我还尝试以编程方式膨胀MapFragment:
mMapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentByTag(MAP_FRAGMENT_TAG);
if (mMapFragment == null) {
mMapFragment = SupportMapFragment.newInstance();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.add(android.R.id.content, mMapFragment, MAP_FRAGMENT_TAG);
fragmentTransaction.commit();
}
但这不会解决错误。
可以使用Google的MapFragment / SupportMapFragment来操作我的应用程序中的内容。 什么可能导致这种行为?
希望你能帮助我。似乎在给地图充气后ClassLoader发生了变化。不知道为什么,但手动调用后
Thread.currentThread().setContextClassLoader(BaseActivity.cLoader);
关闭地图片段后,错误消失。希望它有所帮助:)