添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
力能扛鼎的烤面包  ·  SYSUTCDATETIME ...·  7 月前    · 
叛逆的灌汤包  ·  Python ...·  1 年前    · 
有情有义的馒头  ·  $ cat No such file ...·  1 年前    · 

Im trying to use jetpack navigation to navigate from a Fragment to a BottomSheetDialogFragment but every time I try to navigate it just crash the app saying it cannot find the class name.

mobile_navigation.xml

<fragment  
  android:id="@+id/home_dest"  
  android:name="TestProject.Fragment.HomeFragment">  
    <action  
            android:id="@+id/action_home_to_bottom_sheet"  
            app:destination="@id/bottom_dialog"  
            app:enterAnim="@anim/slide_in_right"  
            app:exitAnim="@anim/slide_out_left"  
            app:popEnterAnim="@anim/slide_in_left"  
            app:popExitAnim="@anim/slide_out_right" /></fragment>  
<dialog  
  android:id="@+id/bottom_dialog"  
  android:name="TestProject.Dialog.BottomDialog" />  

BottomDialog.cs

namespace TestProject.Dialog  
    public class BottomDialog : BottomSheetDialogFragment  
        public override View? OnCreateView(LayoutInflater inflater, ViewGroup? container, Bundle? savedInstanceState)  
            base.OnCreateView(inflater, container, savedInstanceState);  
            return inflater.Inflate(Resource.Layout.bottom_sheet_layout, container, false);  

HomeFragment.cs button click navigation

private void OnButtonClick(object sender, EventArgs e)  
    var nav = Navigation.FindNavController(Activity, Resource.Id.my_nav_host_fragment);  
    nav.Navigate(Resource.Id.action_home_to_bottom_sheet);  

Error

AndroidX.Fragment.App.Fragment+InstantiationException: Unable to instantiate fragment TestProject.Dialog.BottomDialog: make sure class name exists ---> Java.Lang.ClassNotFoundException: TestProject.Dialog.BottomDialog ---> Java.Lang.ClassNotFoundException: Didn't find class "TestProject.Dialog.BottomDialog" on path: DexPathList[[zip file "/data/app/~~aFH8kN7HhPmbIpV2HNo5Pw==/"package_name"-iUb68ulDoLpefgk2DFn_XQ==/base.apk"],nativeLibraryDirectories=[/data/app/~~aFH8kN7HhPmbIpV2HNo5Pw==/package_name-iUb68ulDoLpefgk2DFn_XQ==/lib/arm64, /data/app/~~aFH8kN7HhPmbIpV2HNo5Pw==/package_name-iUb68ulDoLpefgk2DFn_XQ==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64]] 12-21 23:38:50.355 E/AppCenterXamarinCrashes(21237):    --- End of inner exception stack trace --- 12-21 23:38:50.355 E/AppCenterXamarinCrashes(21237):    --- End of inner exception stack trace ---  

With all of this, I get a crash saying it can't find the class named BottomDialog which is impossible because if I change on the mobile_navigation the tag from <dialog to <fragment it can indeed navigate but lose all the behavior that a bottom Sheet must have. I dont know if im missing something or if it's just something regarding xamarin that does not work.

Does anyone knows what might be causing this and why? im out of ideas

Already tried to clean/rebuild, and reinstall nuggets, and still no good.

@Leon Lu (Shanghai Wicresoft Co,.Ltd.)

I thought you had a solution, from your comments above, and that was why I asking for your solution. So do you have one or not?

I'll attach my test app here, but I'm only guessing that is coded the same way as @Hugo G 's app.

I've never attempted to use a Dialog in a nav_graph in any of the NavigationGraph projects I've posted. I've explained my reasons re nav_graph limitations in the NavigationGraph.docx, but I looked up a couple of examples and as far as I can see @Hugo G was coding it as in the examples I saw, so it should have worked.

The class not found exception is common enough with a misspelled class name, but I've never seen it called from the androidx.navigation.fragment.DialogFragmentNavigator.navigate before obviously since my usual code would never be calling that code, since I don't use dialogs in nav_graphs.

https://github.com/gmck/NavigationDialogTest

the full error is the following
Process: com.companyname.navigationdialogtest, PID: 19197
androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.companyname.navigationdialogtest.dialogs.BottomDialog: make sure class name exists
at androidx.fragment.app.FragmentFactory.loadFragmentClass(FragmentFactory.java:97)
at androidx.fragment.app.Fragment.instantiate(Fragment.java:661)
at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:57)
at androidx.fragment.app.FragmentManager$3.instantiate(FragmentManager.java:507)
at androidx.navigation.fragment.DialogFragmentNavigator.navigate(DialogFragmentNavigator.kt:130)
at androidx.navigation.fragment.DialogFragmentNavigator.navigate(DialogFragmentNavigator.kt:118)
at androidx.navigation.NavController.navigateInternal(NavController.kt:260)
at androidx.navigation.NavController.navigate(NavController.kt:1719)
at androidx.navigation.NavController.navigate(NavController.kt:1545)
at androidx.navigation.NavController.navigate(NavController.kt:1472)
at androidx.navigation.NavController.navigate(NavController.kt:1454)
at androidx.navigation.NavController.navigate(NavController.kt:1437)
at mono.android.view.View_OnClickListenerImplementor.n_onClick(Native Method)
at mono.android.view.View_OnClickListenerImplementor.onClick(View_OnClickListenerImplementor.java:31)
at android.view.View.performClick(View.java:7506)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1219)
at android.view.View.performClickInternal(View.java:7483)
at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
at android.view.View$PerformClick.run(View.java:29341)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7872)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Caused by: java.lang.ClassNotFoundException: com.companyname.navigationdialogtest.dialogs.BottomDialog
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:454)
at androidx.fragment.app.FragmentFactory.loadClass(FragmentFactory.java:53)
at androidx.fragment.app.FragmentFactory.loadFragmentClass(FragmentFactory.java:94)
at androidx.fragment.app.Fragment.instantiate(Fragment.java:661) 
at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:57) 
at androidx.fragment.app.FragmentManager$3.instantiate(FragmentManager.java:507) 
at androidx.navigation.fragment.DialogFragmentNavigator.navigate(DialogFragmentNavigator.kt:130) 
at androidx.navigation.fragment.DialogFragmentNavigator.navigate(DialogFragmentNavigator.kt:118) 
at androidx.navigation.NavController.navigateInternal(NavController.kt:260) 
at androidx.navigation.NavController.navigate(NavController.kt:1719) 
at androidx.navigation.NavController.navigate(NavController.kt:1545) 
at androidx.navigation.NavController.navigate(NavController.kt:1472) 
at androidx.navigation.NavController.navigate(NavController.kt:1454) 
at androidx.navigation.NavController.navigate(NavController.kt:1437) 
at mono.android.view.View_OnClickListenerImplementor.n_onClick(Native Method) 
at mono.android.view.View_OnClickListenerImplementor.onClick(View_OnClickListenerImplementor.java:31) 
at android.view.View.performClick(View.java:7506) 
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1219) 
at android.view.View.performClickInternal(View.java:7483) 
at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0) 
at android.view.View$PerformClick.run(View.java:29341) 
at android.os.Handler.handleCallback(Handler.java:942) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loopOnce(Looper.java:201) 
at android.os.Looper.loop(Looper.java:288) 
at android.app.ActivityThread.main(ActivityThread.java:7872) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) 
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.companyname.navigationdialogtest.dialogs.BottomDialog" on path: DexPathList[[zip file "/data/app/~~3OyG_7la9ZenUDf4EJWJOA==/com.companyname.navigationdialogtest-sVLl4WaldoDmb1hN2TvCEw==/base.apk"],nativeLibraryDirectories=[/data/app/~~3OyG_7la9ZenUDf4EJWJOA==/com.companyname.navigationdialogtest-sVLl4WaldoDmb1hN2TvCEw==/lib/arm64, /data/app/~~3OyG_7la9ZenUDf4EJWJOA==/com.companyname.navigationdialogtest-sVLl4WaldoDmb1hN2TvCEw==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at java.lang.Class.classForName(Native Method) 
at java.lang.Class.forName(Class.java:454) 
at androidx.fragment.app.FragmentFactory.loadClass(FragmentFactory.java:53) 
at androidx.fragment.app.FragmentFactory.loadFragmentClass(FragmentFactory.java:94) 
at androidx.fragment.app.Fragment.instantiate(Fragment.java:661) 
at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:57) 
at androidx.fragment.app.FragmentManager$3.instantiate(FragmentManager.java:507) 
at androidx.navigation.fragment.DialogFragmentNavigator.navigate(DialogFragmentNavigator.kt:130) 
at androidx.navigation.fragment.DialogFragmentNavigator.navigate(DialogFragmentNavigator.kt:118) 
at androidx.navigation.NavController.navigateInternal(NavController.kt:260) 
at androidx.navigation.NavController.navigate(NavController.kt:1719) 
at androidx.navigation.NavController.navigate(NavController.kt:1545) 
at androidx.navigation.NavController.navigate(NavController.kt:1472) 
at androidx.navigation.NavController.navigate(NavController.kt:1454) 
at androidx.navigation.NavController.navigate(NavController.kt:1437) 
at mono.android.view.View_OnClickListenerImplementor.n_onClick(Native Method) 
at mono.android.view.View_OnClickListenerImplementor.onClick(View_OnClickListenerImplementor.java:31) 
at android.view.View.performClick(View.java:7506) 
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1219) 
at android.view.View.performClickInternal(View.java:7483) 
at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0) 
at android.view.View$PerformClick.run(View.java:29341) 
at android.os.Handler.handleCallback(Handler.java:942) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loopOnce(Looper.java:201) 
at android.os.Looper.loop(Looper.java:288) 
at android.app.ActivityThread.main(ActivityThread.java:7872) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) 

yep, your app is pretty much what I got on my side.
its really weird since just a small change from <dialog to <fragment make it work(without being a bottom sheet ofc) but it does work without throwing that error hence why I think this might be something deeper I don't know..

I´ve follow docs and YouTube videos where on their side it seems to always work, but I can never make it on my side