Fixed
Status Update
Comments
ab...@gmail.com <ab...@gmail.com> #2
As a workaround, your Fragment can set the arguments to an empty Bundle if it is null:
if (arguments == null) {
arguments = Bundle()
}
// Assuming myArgs is set via by navArgs()
val myArg = myArgs.myArg
if (arguments == null) {
arguments = Bundle()
}
// Assuming myArgs is set via by navArgs()
val myArg = myArgs.myArg
yb...@google.com <yb...@google.com>
ya...@google.com <ya...@google.com> #3
Project: platform/frameworks/support
Branch: androidx-master-dev
commit d8c9982a9cac54247134252eea8d8a4cbf757e74
Author: Ian Lake <ilake@google.com>
Date: Fri Mar 15 13:21:12 2019
Avoid sending a null Bundle when NavArguments are present
When using arguments with android:defaultValue="@null",
these attributes are dropped by XmlPullParser, so the
NavArgument does not have a default value set. Change
addInDefaultArgs() to always return a non-null Bundle
if there are NavArguments set at all to ensure that
Safe Args can correctly parse the empty Bundle and
fill in the correct default values.
This also simplifies the process if you're not using
Safe Args since you can requireArguments() and the
proper gets with your default values.
Test: new AddInDefaultArgsTest parameterized test
Fixes: 128531879
Change-Id: I6ec9673100790df03b5aa1d86f74dbec70173095
A navigation/common/src/androidTest/java/androidx/navigation/AddInDefaultArgsTest.kt
M navigation/common/src/main/java/androidx/navigation/NavDestination.java
https://android-review.googlesource.com/930456
https://goto.google.com/android-sha1/d8c9982a9cac54247134252eea8d8a4cbf757e74
Branch: androidx-master-dev
commit d8c9982a9cac54247134252eea8d8a4cbf757e74
Author: Ian Lake <ilake@google.com>
Date: Fri Mar 15 13:21:12 2019
Avoid sending a null Bundle when NavArguments are present
When using arguments with android:defaultValue="@null",
these attributes are dropped by XmlPullParser, so the
NavArgument does not have a default value set. Change
addInDefaultArgs() to always return a non-null Bundle
if there are NavArguments set at all to ensure that
Safe Args can correctly parse the empty Bundle and
fill in the correct default values.
This also simplifies the process if you're not using
Safe Args since you can requireArguments() and the
proper gets with your default values.
Test: new AddInDefaultArgsTest parameterized test
Fixes: 128531879
Change-Id: I6ec9673100790df03b5aa1d86f74dbec70173095
A navigation/common/src/androidTest/java/androidx/navigation/AddInDefaultArgsTest.kt
M navigation/common/src/main/java/androidx/navigation/NavDestination.java
yb...@google.com <yb...@google.com> #4
We've fixed this for Navigation 2.1.0-alpha01 at the library level, rather than only in Safe Args. Destinations with any argument will have a non-null Bundle.
ab...@gmail.com <ab...@gmail.com> #5
I'm still getting the error with "androidx.navigation:navigation-safe-args-gradle-plugin:2.1.0-alpha02"
<argument
android:name="filter"
android:defaultValue="@null"
app:nullable="true"
app:argType="***.ConsultationsFilter"
/>
---------
class TestFragment : androidx.fragment.app.Fragment() {
private val args by navArgs<TestFragment>()
...
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
....
val filter = args.filter // <-- throws null argument exception
}
<argument
android:name="filter"
android:defaultValue="@null"
app:nullable="true"
app:argType="***.ConsultationsFilter"
/>
---------
class TestFragment : androidx.fragment.app.Fragment() {
private val args by navArgs<TestFragment>()
...
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
....
val filter = args.filter // <-- throws null argument exception
}
ab...@gmail.com <ab...@gmail.com> #6
upd line: private val args by navArgs<TestFragmentArg>()
ya...@google.com <ya...@google.com> #7
Re #5/6 - please file a new bug with a sample project that reproduces your issue.
da...@google.com <da...@google.com>
ai...@gmail.com <ai...@gmail.com> #8
i am facing null bundle exception while using nav graph arguments even i have set the default arguments in
nav graph and also check null in code
here is my sample code of Kotlin
private val args : BottomSheetCartFragmentArgs? by navArgs()
arg?.let {
product = it.product
isFromCart = it.isFromCart
screenName = it.screenName
}
Nav graph arguments
<argument
android:name="product"
app:argType="com.dawaai.dawaaidukaan.model.Product"
/>
<argument
android:name="isFromCart"
android:defaultValue="false"
app:argType="boolean"
/>
<argument
android:name="screenName"
app:argType="string"
android:defaultValue="recreate_order"/>
nav graph and also check null in code
here is my sample code of Kotlin
private val args : BottomSheetCartFragmentArgs? by navArgs()
arg?.let {
product = it.product
isFromCart = it.isFromCart
screenName = it.screenName
}
Nav graph arguments
<argument
android:name="product"
app:argType="com.dawaai.dawaaidukaan.model.Product"
/>
<argument
android:name="isFromCart"
android:defaultValue="false"
app:argType="boolean"
/>
<argument
android:name="screenName"
app:argType="string"
android:defaultValue="recreate_order"/>
[Deleted User] <[Deleted User]> #9
Re #8 - please file a new bug with a sample project that reproduces your issue.
Description
Version used: 1.1.0
Devices/Android versions reproduced on: all
I have two classes:
parent class - parent.kt
child class - child.kt
and standart dao.
But allways return data with null value - contactDetails. In generated code i will see next:
```
//...
final ContactDetails _tmpContactDetails;
if (! (_cursor.isNull(_cursorIndexOfCountryCode) && _cursor.isNull(_cursorIndexOfPhoneNumber))) {
final String _tmpCountryCode;
_tmpCountryCode = _cursor.getString(_cursorIndexOfCountryCode);
final String _tmpPhoneNumber;
_tmpPhoneNumber = _cursor.getString(_cursorIndexOfPhoneNumber);
_tmpContactDetails = new ContactDetails(_tmpCountryCode,_tmpPhoneNumber);
} else {
_tmpContactDetails = null;
}
_item = new ShareAccount(_tmpShareId,_tmpEntityId,_tmpUserId,_tmpOwnerId,null,_tmpCreatedAt,_tmpModifiedAt,_tmpAction);
/....
```
that is, regardless of the value of _tmpContactDetails, it will eventually be set to null.