膨胀MapView时出错

时间:2017-03-21 13:36:40

标签: android maps android-mapview android-inflate

我正在尝试在片段中显示MapView,当我给它充气时出现错误:

<?php

class Presenter
{
    public static function listTables(array $array)
    {
        $html = '';

        $base = Flight::get('base');

        $counter = 0;
        foreach ($array as $arrayitem) {
            $counter ++;

            $html .= <<< HTML
            <li><a href="$base/table/$arrayitem">$arrayitem</a></li>
HTML;
        }

        return $html;
    }

    public static function listTableData(array $array, $fieldTypes = array())
    {
        //$fieldTypes = convertFieldTypesEditable($fieldTypes);

        $html = '<table class="table table-striped table-bordered table-hover">' . "\n";
        $html .= '<thead>' . "\n";

        // build headings
        foreach ($array[0] as $head => $value) {
            $html .= "<th>$head</th>" . "\n";
        }

        $html .= '</thead>' . "\n";

        // build body
        $html .= '<tbody>' . "\n";

        //pretty_print($array);

        foreach ($array as $subArray) {
            $html .= '<tr>' . "\n";

            foreach ($subArray as $value) {
                $html .= '<td style="white-space: nowrap !important;">' . $value . '</td>' . "\n";
            }

            $html .= '</tr>' . "\n";
        }

        $html .= '</tbody>' . "\n";
        $html .= '</table>' . "\n";

        return $html;
    }
}

有什么想法吗?这是我放置MapView的XML:

    03-21 14:34:44.234 32691-32691/com.example.javiersanzrozalen.fatrunners E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.javiersanzrozalen.fatrunners, PID: 32691
android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class com.google.android.gms.maps.MapView
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class com.google.android.gms.maps.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:645)                                                                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)                                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)                                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:495)                                                                                              at android.view.LayoutInflater.inflate(LayoutInflater.java:426)                                                                                                at com.example.javiersanzrozalen.fatrunners.Fragments.NuevaCarreraFragment.onCreateView(NuevaCarreraFragment.java:53)                                                                                                 at android.support.v4.app.Fragment.performCreateView(Fragment.java:2192)                                                                                               at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299)                                                                                                at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)                                                                                               at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)                                                                                            at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:758)                                                                                               at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363                                                                                             at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149)                                                                                            at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103)
                                                                                                  at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2013)                                                                                               at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:710)                                                                                                  at android.os.Handler.handleCallback(Handler.java:751)                                                                                                  at android.os.Handler.dispatchMessage(Handler.java:95)                                                                                                  at android.os.Looper.loop(Looper.java:154)                                                                                                  at android.app.ActivityThread.main(ActivityThread.java:6119)                                                                                                  at java.lang.reflect.Method.invoke(Native Method)                                                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)                                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)                                                                                               Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/safeparcel/AbstractSafeParcelable;                                                                                                 at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)                                                                                                  at com.google.android.gms.maps.MapView.<init>(Unknown Source)                                                                                                  at java.lang.reflect.Constructor.newInstance0(Native Method)                                                                                                   at java.lang.reflect.Constructor.newInstance(Constructor.java:430)                                                                                                   at android.view.LayoutInflater.createView(LayoutInflater.java:645)                                                                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)                                                                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)                                                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:495)                                                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:426)                                                                                                   at com.example.javiersanzrozalen.fatrunners.Fragments.NuevaCarreraFragment.onCreateView(NuevaCarreraFragment.java:53)                                                                                                   at android.support.v4.app.Fragment.performCreateView(Fragment.java:2192)                                                                                                 at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299)                                                                                                 at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)                                                                                                   at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)                                                                                                   at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:758)                                                                                                  at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363                                                                                                  at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149)                                                                                                   at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103)                                                                                                  at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2013) 
                                                                                                  at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:710) 
                                                                                                  at android.os.Handler.handleCallback(Handler.java:751) 
                                                                                                  at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                                                  at android.os.Looper.loop(Looper.java:154) 
                                                                                                  at android.app.ActivityThread.main(ActivityThread.java:6119) 
                                                                                                  at java.lang.reflect.Method.invoke(Native Method) 
                                                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
                                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
                                                                                               Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable" on path: DexPathList[[zip file "/data/app/com.example.javiersanzrozalen.fatrunners-2/base.apk", zip file "/data/app/com.example.javiersanzrozalen.fatrunners-2/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.javiersanzrozalen.fatrunners-2/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.javiersanzrozalen.fatrunners-2/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.javiersanzrozalen.fatrunners-2/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.javiersanzrozalen.fatrunners-2/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.javiersanzrozalen.fatrunners-2/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.javiersanzrozalen.fatrunners-2/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.javiersanzrozalen.fatrunners-2/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.javiersanzrozalen.fatrunners-2/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.javiersanzrozalen.fatrunners-2/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.javiersanzrozalen.fatrunners-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.javiersanzrozalen.fatrunners-2/lib/x86, /system/lib, /vendor/lib]]
    03-21 14:34:44.234 32691-32691/com.example.javiersanzrozalen.fatrunners E/AndroidRuntime:     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                                                                                                  at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
                                                                                                  at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                                                                                                    ... 27 more

更新

最后解决了它编译推荐的最新版Google地图库的问题。

1 个答案:

答案 0 :(得分:0)

You are attempting to use the original version of Google Maps support for Android (com.google.android.maps). We refer to that now as Maps V1.

This will not work, as Maps V1 has been deprecated for over two years. You can no longer get API keys for it, so even if your code would be correct, it would not work. The crash is because the old MapView had to be used inside of a MapActivity, as the error indicates.

The current version of Google Maps support for Android — Maps V2 — has a very different API and does not involve classes in the com.google.android.maps package.