0

I’ve got my structure as Activity -> Navigation Fragment Container which has fragments that also contain a Navigation Fragment Container however when I navigate from start destination to localMusicView it works however its child Navigation Fragment Container fragment throws an inflation error and parceable don’t support default values error (Line at which this error occurs is stated in logs) . I know its not an error of my using the wrong graph I this worked correctly without using args and my dataclasses are using @Parcelize and @Entity ( for room database) annonations. (given below) I’ve tried setting the arrays to null as a default value, doesn’t work and even chainging the start destination to a placeholder but still gives same error. I’ve also included the functions im using to pass the args (also im using safe-args plugin) , ive tried when using a try catch for getting the parcelable values (it does have any effect on the outcome) as no default values mean its null which throws an error.


@Entity 

@Parcelize 

data class Album( 

    var title: String = "", 

    var albumArtist: String = "", 

    var pinned: Boolean = false, 

    var songs:ArrayList<Song> = arrayListOf(), 

    var songsIDs:ArrayList<String> = arrayListOf(), 

    val imgURL: String = "", 

    @PrimaryKey(autoGenerate = false) val id: String = "" 

) : Parcelable { 

    …. 

}  


<navigation …. > 

<action android:id="@+id/action_global_local_musicview" app:destination="@id/localMusicView"/>    

    <fragment 

        android:id="@+id/localMusicView" 

        android:name="com.deathsdoor.chillbackmusicplayer.ui.fragment.LocalMusicView" 

        android:label="fragment_local_music_view" 

        tools:layout="@layout/fragment_local_music_view" /> 

</navigation> 


<?xml version="1.0" encoding="utf-8"?> 

<navigation 

    xmlns:android="http://schemas.android.com/apk/res/android" 

    xmlns:app="http://schemas.android.com/apk/res-auto" 

    xmlns:tools="http://schemas.android.com/tools" 

    android:id="@+id/nav_local_music_view.xml" 

    app:startDestination="@id/placeholder"> 

    <action 

        android:id="@+id/action_global_nach_albumRecyclerView" 

        app:destination="@id/albumRecyclerView" /> 

    <action 

        android:id="@+id/action_global_nach_songRecyclerView" 

        app:destination="@id/songRecyclerView" /> 

    <fragment 

        android:id="@+id/albumRecyclerView" 

        android:name="com.deathsdoor.chillbackmusicplayer.ui.fragment.AlbumRecyclerView" 

        android:label="fragment_album_recycler_view" 

        tools:layout="@layout/fragment_album_recycler_view" > 

        <argument 

            android:name="displayedAlbums" 

            app:argType="com.deathsdoor.chillbackmusicplayer.data.dataclasses.Album[]" /> 

// logs shows error occurs on this line  

        <argument 

            android:name="orientation" 

            app:argType="com.deathsdoor.chillbackmusicplayer.data.Contants$ORIENTATION" 

            android:defaultValue="VERTICAL" /> 

        <argument 

            android:name="disableForwardNavigation" 

            app:argType="boolean" 

            android:defaultValue="false" /> 

    </fragment> 

    <fragment 

        android:id="@+id/songRecyclerView" 

        android:name="com.deathsdoor.chillbackmusicplayer.ui.fragment.SongRecyclerView" 

        android:label="SongRecyclerView" > 

        <argument 

            android:name="displaySongs" 

            app:argType="com.deathsdoor.chillbackmusicplayer.data.dataclasses.Song[]" 

            app:nullable="true" /> 

        <argument 

            android:name="orientation" 

            app:argType="com.deathsdoor.chillbackmusicplayer.data.Contants$ORIENTATION" 

            android:defaultValue="VERTICAL" /> 

        <argument 

            android:name="disableForwardNavigation" 

            app:argType="boolean" 

            android:defaultValue="false" /> 

    </fragment> 

    <fragment android:id="@+id/placeholder" /> 

</navigation> 

Minimezed Logs are


FATAL EXCEPTION: main 

    Process: com.deathsdoor.chillbackmusicplayer, PID: 19610 

    android.view.InflateException: Binary XML file line #18: Binary XML file line #18: Error inflating class androidx.fragment.app.FragmentContainerView 

    Caused by: android.view.InflateException: Binary XML file line #18: Error inflating class androidx.fragment.app.FragmentContainerView 

Caused by: java.lang.RuntimeException: Exception inflating com.deathsdoor.chillbackmusicplayer:navigation/nav_local_music_view line 22 

…….. 

  at com.deathsdoor.chillbackmusicplayer.databinding.FragmentLocalMusicViewBinding.inflate(FragmentLocalMusicViewBinding.java:50) 

        at com.deathsdoor.chillbackmusicplayer.ui.fragment.LocalMusicView.onCreateView(LocalMusicView.kt:23) …… 

Caused by: java.lang.UnsupportedOperationException: Parcelables don't support default values. 

        at androidx.navigation.NavType$ParcelableType.parseValue(NavType.kt:593) 

  at com.deathsdoor.chillbackmusicplayer.databinding.FragmentLocalMusicViewBinding.inflate(FragmentLocalMusicViewBinding.java:50)  

        at com.deathsdoor.chillbackmusicplayer.ui.fragment.LocalMusicView.onCreateView(LocalMusicView.kt:23)  

Bundles functions


fun List<Album>.createAlbumRecyclerViewBundle(orientation: Contants.ORIENTATION? = Contants.ORIENTATION.VERTICAL, disableForwardNavigation:Boolean = false): Bundle { 

        val bundle =  Bundle() 

        bundle.putParcelableArrayList(DISPLAY_ALBUMS, ArrayList(this)) 

        if(orientation == null) bundle.putParcelable(ORIENTATION, Contants.ORIENTATION.VERTICAL) 

        else bundle.putParcelable(ORIENTATION,orientation) 

        bundle.putBoolean(DISABLE_FORWARD_NAVIGATION,disableForwardNavigation) 

        return bundle 

    } 

    internal inline fun Bundle.getAlbumRecyclerViewValues(crossinline action: (albums: List<Album>?, orientation: Contants.ORIENTATION,disableForwardNavigation:Boolean) -> Unit) { 

        try { 

            action( 

                this.getParcelableArrayList(DISPLAY_ALBUMS), 

                getParcelable(ORIENTATION) ?: Contants.ORIENTATION.VERTICAL, 

                getBoolean(DISABLE_FORWARD_NAVIGATION) 

            ) 

        } 

        catch (e:Exception){  action( 

            null, 

            getParcelable(ORIENTATION) ?: Contants.ORIENTATION.VERTICAL, 

            getBoolean(DISABLE_FORWARD_NAVIGATION) 

        ) } 

    } 

 

    fun List<Song>?.createSongRecyclerViewBundle(orientation:Contants.ORIENTATION? = null): Bundle { 

        val bundle =  Bundle() 

        bundle.putParcelableArrayList(DISPLAY_SONGS, this as ArrayList<Song>) 

        if(orientation == null) bundle.putParcelable(ORIENTATION, Contants.ORIENTATION.VERTICAL) 

        else bundle.putParcelable(ORIENTATION,orientation) 

        return bundle 

    } 

TylerH
  • 20,799
  • 66
  • 75
  • 101
Aarav Shah
  • 55
  • 1
  • 7

0 Answers0