在使用此处地图 SDK 时膨胀异常
Inflate Exception while using here maps SDK
我正在使用此处的地图,但出现此错误:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lifesessentia.tat_manager/com.lifesessentia.tat.MapActivity}: android.view.InflateException: Binary XML file line #46: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2338)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access0(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5299)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
at dalvik.system.NativeStart.main(Native Method)
Caused by:
android.view.InflateException: Binary XML file line #46: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
Caused by: java.lang.NullPointerException
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2373)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:374)
at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:33)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:75)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
我已遵循 SDK 用户指南。我可以将 SDK 用于具有不同应用程序 ID 的其他应用程序,但不能用于此应用程序。
这是我的 activity_map:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:minHeight="?attr/actionBarSize"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:titleTextColor="@android:color/white"
android:theme="@style/ToolbarTheme"
app:titleTextAppearance="@style/Toolbar.TitleText"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:background="?attr/colorPrimary">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textStyle="bold"
android:textColor="@android:color/white"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_gravity="left"
/>
</android.support.v7.widget.Toolbar>
<ListView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="@+id/the_List"
/>
<!-- Map Fragment embedded with the map object -->
<fragment
class="com.here.android.mpa.mapping.MapFragment"
android:id="@+id/mapfragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
在logcat中可以看出错误是由于片段class处的空指针异常导致的。我该如何解决这个错误?
有时我会在 gradle 条消息中收到这些警告:
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.here.sdk.analytics.internal.c) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:compiler that did not target the modern .class file format. The recommended
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:indicate that it is *not* an inner class.
Error:this warning is that reflective operations on this class will incorrectly
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.here.sdk.analytics.internal.l) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:indicate that it is *not* an inner class.
Error:(com.here.sdk.analytics.internal.o) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:indicate that it is *not* an inner class.
Error:this warning is that reflective operations on this class will incorrectly
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:(com.here.sdk.analytics.internal.b) that doesn't come with an
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is *not* an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.here.sdk.analytics.internal.r) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:indicate that it is *not* an inner class.
Error:(com.here.sdk.analytics.internal.h) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:compiler that did not target the modern .class file format. The recommended
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is *not* an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.here.sdk.analytics.internal.a.c) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:indicate that it is *not* an inner class.
Error:(com.here.sdk.analytics.internal.j) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:this warning is that reflective operations on this class will incorrectly
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:indicate that it is *not* an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.here.sdk.analytics.internal.k) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
这是我的清单:
<?xml version="1.0" encoding="utf-8" ?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.lifesessentia.tat">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:hardwareAccelerated="true"
android:largeHeap="true"
android:theme="@style/AppTheme">
<activity android:name=".MapActivity" android:screenOrientation="portrait" />
<activity android:name=".Login_Activity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Plan_finished_activity"
android:screenOrientation="portrait" />
<service android:name=".Database_service" />
<service android:name=".Download_and_Store_Service" />
<service android:name=".Location_alert_service" />
<service
android:name="com.here.android.mpa.service.MapService"
android:label="HereMapService"
android:process="global.Here.Map.Service.v2"
android:exported="true">
<intent-filter>
<action android:name="com.here.android.mpa.service.MapService" />
</intent-filter>
</service>
<meta-data android:name="com.here.android.maps.appid"
android:value="----" />
<meta-data android:name="com.here.android.maps.apptoken"
android:value="----" />
<meta-data android:name="com.here.android.maps.license.key"
android:value="----" />
</application>
</manifest>
其实我觉得问题很简单:
请更改代码:
<fragment
class="com.here.android.mpa.mapping.MapFragment"
android:id="@+id/mapfragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
收件人:
<com.here.android.mpa.mapping.MapView
android:id="@+id/mapfragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
问题出在 onCreate()
我在 super.onCreate()
之前调用了初始化函数,我通过先调用 super 方法然后调用初始化方法来解决。我从没想过问题是由于这个愚蠢的错误造成的,花了 1 周的时间才找到这个!
我正在使用此处的地图,但出现此错误:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lifesessentia.tat_manager/com.lifesessentia.tat.MapActivity}: android.view.InflateException: Binary XML file line #46: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2338)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access0(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5299)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
at dalvik.system.NativeStart.main(Native Method)
Caused by:
android.view.InflateException: Binary XML file line #46: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
Caused by: java.lang.NullPointerException
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2373)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:374)
at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:33)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:75)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
我已遵循 SDK 用户指南。我可以将 SDK 用于具有不同应用程序 ID 的其他应用程序,但不能用于此应用程序。
这是我的 activity_map:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:minHeight="?attr/actionBarSize"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:titleTextColor="@android:color/white"
android:theme="@style/ToolbarTheme"
app:titleTextAppearance="@style/Toolbar.TitleText"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:background="?attr/colorPrimary">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textStyle="bold"
android:textColor="@android:color/white"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_gravity="left"
/>
</android.support.v7.widget.Toolbar>
<ListView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="@+id/the_List"
/>
<!-- Map Fragment embedded with the map object -->
<fragment
class="com.here.android.mpa.mapping.MapFragment"
android:id="@+id/mapfragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
在logcat中可以看出错误是由于片段class处的空指针异常导致的。我该如何解决这个错误?
有时我会在 gradle 条消息中收到这些警告:
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.here.sdk.analytics.internal.c) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:compiler that did not target the modern .class file format. The recommended
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:indicate that it is *not* an inner class.
Error:this warning is that reflective operations on this class will incorrectly
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.here.sdk.analytics.internal.l) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:indicate that it is *not* an inner class.
Error:(com.here.sdk.analytics.internal.o) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:indicate that it is *not* an inner class.
Error:this warning is that reflective operations on this class will incorrectly
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:(com.here.sdk.analytics.internal.b) that doesn't come with an
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is *not* an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.here.sdk.analytics.internal.r) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:indicate that it is *not* an inner class.
Error:(com.here.sdk.analytics.internal.h) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:compiler that did not target the modern .class file format. The recommended
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is *not* an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.here.sdk.analytics.internal.a.c) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:indicate that it is *not* an inner class.
Error:(com.here.sdk.analytics.internal.j) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:this warning is that reflective operations on this class will incorrectly
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:indicate that it is *not* an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.here.sdk.analytics.internal.k) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
这是我的清单:
<?xml version="1.0" encoding="utf-8" ?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.lifesessentia.tat">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:hardwareAccelerated="true"
android:largeHeap="true"
android:theme="@style/AppTheme">
<activity android:name=".MapActivity" android:screenOrientation="portrait" />
<activity android:name=".Login_Activity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Plan_finished_activity"
android:screenOrientation="portrait" />
<service android:name=".Database_service" />
<service android:name=".Download_and_Store_Service" />
<service android:name=".Location_alert_service" />
<service
android:name="com.here.android.mpa.service.MapService"
android:label="HereMapService"
android:process="global.Here.Map.Service.v2"
android:exported="true">
<intent-filter>
<action android:name="com.here.android.mpa.service.MapService" />
</intent-filter>
</service>
<meta-data android:name="com.here.android.maps.appid"
android:value="----" />
<meta-data android:name="com.here.android.maps.apptoken"
android:value="----" />
<meta-data android:name="com.here.android.maps.license.key"
android:value="----" />
</application>
</manifest>
其实我觉得问题很简单:
请更改代码:
<fragment
class="com.here.android.mpa.mapping.MapFragment"
android:id="@+id/mapfragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
收件人:
<com.here.android.mpa.mapping.MapView
android:id="@+id/mapfragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
问题出在 onCreate()
我在 super.onCreate()
之前调用了初始化函数,我通过先调用 super 方法然后调用初始化方法来解决。我从没想过问题是由于这个愚蠢的错误造成的,花了 1 周的时间才找到这个!