mapbox-navigation-android icon indicating copy to clipboard operation
mapbox-navigation-android copied to clipboard

Crash when using InstructionView in xml

Open xenazakharova opened this issue 9 years ago • 11 comments

Platform: Android 6.0.1

build.gradle dependencies { compile 'com.mapbox.mapboxsdk:mapbox-android-navigation:0.6.3' compile ('com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.6.3') { transitive = true } }

I've got an exception

Caused by: android.view.InflateException: Binary XML file line #29: Error inflating class com.mapbox.services.android.navigation.ui.v5.instruction.InstructionView

xenazakharova avatar Oct 24 '17 07:10 xenazakharova

@xenazakharova Thanks for the feedback, can you please provide the full stack trace? Thank you

danesfeder avatar Oct 25 '17 21:10 danesfeder

Process: com.parko.android, PID: 27958 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.parko.android/com.parko.android.activities.RouteActivity}: android.view.InflateException: Binary XML file line #29: Binary XML file line #29: Error inflating class com.mapbox.services.android.navigation.ui.v5.instruction.InstructionView at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2440) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2500) at android.app.ActivityThread.access$900(ActivityThread.java:163) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1362) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5585) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620) Caused by: android.view.InflateException: Binary XML file line #29: Binary XML file line #29: Error inflating class com.mapbox.services.android.navigation.ui.v5.instruction.InstructionView at android.view.LayoutInflater.inflate(LayoutInflater.java:539) at android.view.LayoutInflater.inflate(LayoutInflater.java:423) at com.parko.android.fragment.RouteMapboxFragment.onCreateView(RouteMapboxFragment.java:314) at android.app.Fragment.performCreateView(Fragment.java:2229) at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:973) at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1148) at android.app.BackStackRecord.run(BackStackRecord.java:793) at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1535) at android.app.FragmentController.execPendingActions(FragmentController.java:325) at android.app.Activity.performStart(Activity.java:6294) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2403) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2500)  at android.app.ActivityThread.access$900(ActivityThread.java:163)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1362)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:148)  at android.app.ActivityThread.main(ActivityThread.java:5585)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)  Caused by: android.view.InflateException: Binary XML file line #29: Error inflating class com.mapbox.services.android.navigation.ui.v5.instruction.InstructionView at android.view.LayoutInflater.createView(LayoutInflater.java:645) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) at android.view.LayoutInflater.inflate(LayoutInflater.java:515) at android.view.LayoutInflater.inflate(LayoutInflater.java:423)  at com.parko.android.fragment.RouteMapboxFragment.onCreateView(RouteMapboxFragment.java:314)  at android.app.Fragment.performCreateView(Fragment.java:2229)  at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:973)  at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1148)  at android.app.BackStackRecord.run(BackStackRecord.java:793)  at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1535)  at android.app.FragmentController.execPendingActions(FragmentController.java:325)  at android.app.Activity.performStart(Activity.java:6294)  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2403)  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2500)  at android.app.ActivityThread.access$900(ActivityThread.java:163)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1362)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:148)  at android.app.ActivityThread.main(ActivityThread.java:5585)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)  Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.newInstance(Native Method) at android.view.LayoutInflater.createView(LayoutInflater.java:619) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)  at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)  at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)  at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)  at android.view.LayoutInflater.inflate(LayoutInflater.java:515)  at android.view.LayoutInflater.inflate(LayoutInflater.java:423)  at com.parko.android.fragment.RouteMapboxFragment.onCreateView(RouteMapboxFragment.java:314)  at android.app.Fragment.performCreateView(Fragment.java:2229)  at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:973)  at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1148)  at android.app.BackStackRecord.run(BackStackRecord.java:793)  at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1535)  at android.app.FragmentController.execPendingActions(FragmentController.java:325)  at android.app.Activity.performStart(Activity.java:6294)  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2403)  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2500)  at android.app.ActivityThread.access$900(ActivityThread.java:163)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1362)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:148)  at android.app.ActivityThread.main(ActivityThread.java:5585)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)  Caused by: android.view.InflateException: Binary XML file line #10: Binary XML file line #16: Error inflating class at android.view.LayoutInflater.inflate(LayoutInflater.java:539) at android.view.LayoutInflater.inflate(LayoutInflater.java:423) at android.view.LayoutInflater.inflate(LayoutInflater.java:374) at android.view.View.inflate(View.java:19986) at com.mapbox.services.android.navigation.ui.v5.instruction.InstructionView.init(InstructionView.java:224) at com.mapbox.services.android.navigation.ui.v5.instruction.InstructionView.(InstructionView.java:93) at com.mapbox.services.android.navigation.ui.v5.instruction.InstructionView.(InstructionView.java:88) at java.lang.reflect.Constructor.newInstance(Native Method)  at android.view.LayoutInflater.createView(LayoutInflater.java:619)  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)  at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)  at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)  at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)  at android.view.LayoutInflater.inflate(LayoutInflater.java:515)  at android.view.LayoutInflater.inflate(LayoutInflater.java:423)  at com.parko.android.fragment.RouteMapboxFragment.onCreateView(RouteMapboxFragment.java:314)  at android.app.Fragment.performCreateView(Fragment.java:2229)  at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:973)  at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1148)  at android.app.BackStackRecord.run(BackStackRecord.java:793)  at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1535)  at android.app.FragmentController.execPendingActions(FragmentController.java:325)  at android.app.Activity.performStart(Activity.java:6294)  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2403)  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2500)  at android.app.ActivityThread.access$900(ActivityThread.java:163)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1362)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:148)  at android.app.ActivityThread.main(ActivityThread.java:5585)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)  Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class at android.view.LayoutInflater.createView(LayoutInflater.java:645) at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutIn

xenazakharova avatar Oct 26 '17 10:10 xenazakharova

Same issue! Is there a workaound?

josephquzhou avatar Oct 31 '17 13:10 josephquzhou

Are you both using the InstructionView in your XML layouts? Or is this using the NavigationLauncher

danesfeder avatar Oct 31 '17 14:10 danesfeder

I use InstructionView in my activity layout, and use it with MapboxNavigation (not NavigationLauncher). I don't use NavigationLauncher, because it seems to have problem with waypoints during rerouting.

josephquzhou avatar Oct 31 '17 14:10 josephquzhou

Sorry. I forgot to mention. I also try to put InstructionView in a separate xml file and use LayoutInflater.

josephquzhou avatar Oct 31 '17 15:10 josephquzhou

@josephquzhou Looks like a bug in our initialization of the InstructionView by itself. Will look into this when I get a chance. And yeah, I should note in the docs that waypoints aren't currently supported by the NavigationLauncher

danesfeder avatar Oct 31 '17 16:10 danesfeder

@danesfeder Hope the InstructionView initialization bug can be fixed soon. Currently I am stuck in turn-by-turn navigation display without InstructionView or NavigationLauncher. Thanks!

josephquzhou avatar Nov 01 '17 15:11 josephquzhou

I also wait impatiently when the bug will be fixed, I really want to use InstructionView in my development. Thanks!

OksanaZakharova avatar Nov 07 '17 11:11 OksanaZakharova

Hey @xenazakharova @OksanaZakharova @josephquzhou, this bug is due to our use of theming now in these custom Views. When the XML tries to inflate, it looks for the custom ?attr/ tags from the set style for the colors to use for the background, text color, etc. I'm assuming you haven't set a theme including colors for these attributes.

To fix this, simply add: setTheme(R.style.NavigationViewLight);

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.NavigationViewLight);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mock_navigation);
    ...
   }

NavigationViewLight is one of our preset themes we use. But, you can make this completely custom if you'd like, using your own colors. Just make sure you include a colors for each attribute in https://github.com/mapbox/mapbox-navigation-android/blob/master/libandroid-navigation-ui/src/main/res/values/attrs.xml#L15

This is on us, as I have yet to update the docs to clearly explain this / make this straightforward. This will be done when 0.7.0 lands. Thanks for understanding!

device-2017-11-07-101915

danesfeder avatar Nov 07 '17 15:11 danesfeder

@danesfeder Thank you! After adding setTheme(R.style.NavigationViewLight); the initialization of InstructionView is working. I think the reason we made such a mistake is due to lack of examples. Are there code examples of using InstructionView? Thanks!

josephquzhou avatar Nov 07 '17 23:11 josephquzhou