Mrunal Ahirrao Mrunal Ahirrao - 1 month ago 11
Android Question

Inflate Exception while using here maps SDK

I am using here maps but I am getting this error:

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.access$800(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) 


I have followed SDK user guide. I am able to use SDK for other app with different app id but not with this one.

This is my 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>


In logcat it can be seen that error is caused due to null pointer exception at fragment class. How I should solve this error?

Sometimes I get these warnings in gradle messages:

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


This my manifest:

<?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>

Answer

The issue was in onCreate() I was calling initialize function before super.onCreate() and I solved by calling the super method first and then initialization method. I never thought issue was due to this silly mistake, it took 1 week to find this!