1

我在片段中使用谷歌地图。它运作良好,一切都很好。但是当我离开地图片段时,它变得非常奇怪!

我还使用 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();
    }

但这不会解决错误。

可能使用谷歌的 MapFragment / SupportMapFragment 操纵了我的应用程序内部的某些东西。什么可能导致这种行为?

希望你能帮助我。

知道了:

似乎在膨胀地图后 ClassLoader 发生了变化。不知道为什么,但是手动调用后

Thread.currentThread().setContextClassLoader(BaseActivity.cLoader);

关闭地图片段后,错误消失。希望能帮助到你 :)

4

0 回答 0