Android 地图无法在fragment中加载

0 投票

是不能写在fragment中,在加载有  MapView的布局时 报错。

fragment  layout布局:

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.supermap.mapping.MapView
            android:id="@+id/mapView"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </com.supermap.mapping.MapView>


    </RelativeLayout>

错误信息:

Process: com.runto.sport, PID: 20643
    android.view.InflateException: Binary XML file line #12: Binary XML file line #12: Error inflating class com.supermap.mapping.MapView
    Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class com.supermap.mapping.MapView
    Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
        at android.view.LayoutInflater.createView(LayoutInflater.java:656)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:798)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:738)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:832)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
        at android.databinding.DataBindingUtil.inflate(DataBindingUtil.java:126)
        at android.databinding.DataBindingUtil.inflate(DataBindingUtil.java:95)
        at com.runto.sport.fragment.MotionFragment.initBinding(MotionFragment.java:33)
        at com.runto.sport.base.BaseFragment.onCreateView(BaseFragment.java:22)
        at android.support.v4.app.Fragment.performCreateView(Fragment.java:2439)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460)
        at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
        at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:802)
        at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
        at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
        at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
        at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:2243)
        at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:654)
        at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:168)
        at android.support.v4.view.ViewPager.populate(ViewPager.java:1244)
        at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:669)
        at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:631)
        at android.support.v4.view.ViewPager.setCurrentItem(ViewPager.java:612)
        at com.runto.sport.activity.MainActivity.onCheckedChanged(MainActivity.java:104)
        at android.widget.RadioGroup.setCheckedId(RadioGroup.java:173)
        at android.widget.RadioGroup.-wrap0(RadioGroup.java)
        at android.widget.RadioGroup$CheckedStateTracker.onCheckedChanged(RadioGroup.java:351)
        at android.widget.CompoundButton.setChecked(CompoundButton.java:160)
        at android.widget.CompoundButton.toggle(CompoundButton.java:116)
        at android.widget.RadioButton.toggle(RadioButton.java:76)
        at android.widget.CompoundButton.performClick(CompoundButton.java:121)
        at android.view.View$PerformClick.run(View.java:22627)
        at android.os.Handler.handleCallback(Handler.java:846)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:205)
        at android.app.ActivityThread.main(ActivityThread.java:6753)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1216)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1077)
     Caused by: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.runto.sport-2/base.apk"],nativeLibraryDirectories=[/data/app/com.runto.sport-2/lib/arm, /data/app/com.runto.sport-2/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib, /system/vendor/lib, /product/lib]]] couldn't find "libimb.so"
        at java.lang.Runtime.loadLibrary0(Runtime.java:989)
        at java.lang.System.loadLibrary(System.java:1533)
        at com.supermap.data.Environment.LoadWrapJ(Environment.java:455)
        at com.supermap.data.Environment.InternalLoadWrapJ(Environment.java:1093)
        at com.supermap.mapping.g.a(InternalEnvironment.java:22)
        at com.supermap.mapping.MapControl2.<clinit>(MapControl2.java:45)
        at com.supermap.mapping.MapControl.a(MapControl.java:62)
        at com.supermap.mapping.MapControl.<init>(MapControl.java:33)
        at com.supermap.mapping.MapView.a(MapView.java:91)
        at com.supermap.mapping.MapView.<init>(MapView.java:82)

8月 12 分类:  50次浏览 | 用户: 朕丶无所畏惧 (2 分)

1个回答

0 投票

您好,您的代码里面是怎么写的呢?你在fragment类里面重写onActivityCreated方法即可,参考如下:

8月 12 用户: 董懿鑫 名扬四海 (3,093 分)
还行不能解决问题,问题出在  onCreateView 中  inflater.inflate(),引用布局时就已经崩溃。
您好,你是使用的iMobile for Android还是iMobile Lite呢?我看你在上一篇帖子中说明了是Lite,但是你这个是iMobile原生的Android?引用布局崩溃你看一下你的布局文件有写正确吗?可以把你的布局文件贴出来看一下

使用的是:supermap-imobile-9.0.1-103-android-zip-chs(精简绿色包),用的这个包,

layout布局:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">

    <data>

    </data>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.supermap.mapping.MapView
            android:id="@+id/mapView"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </com.supermap.mapping.MapView>


    </RelativeLayout>
</layout>

这是完整的布局代码。

iMobile Lite 与 iMobile for Android 有什么区别?难道我用错了么?

您好,你在build.grandle文件中有配置SourceSets吗,可以参考这篇博客配置一下https://www.jianshu.com/p/d08064bf6b85。iMobile LIte是一种轻量级SDK,功能相对于iMobile for Android较少,iMobile Lite主要是对接在线数据。Fragment和activity是很相似的,mapview也是可以正常在这两种方式加载。

这些我都配置过了,在activity中是正常的,但是应用在fragment中就不行,应该不是so库的问题。
我们很多项目都是在fragment里面写的,而且你的报错信息里面报错so库找不到,我的建议还是先检查一下so库,布局文件有没有写错。如果还是有问题,我稍后私信您一个fragment的demo。

这个问题已经解决了,是我这边代码的问题,Environment未初始化就加载了组件,所以才一直不行,非常感谢你的耐心答疑,五星好评哦!yes

...