NullpointerException when creating a notebook widget
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2024 03:32 AM
To reproduce, execute this line in a notebook (runtime 15.3):
dbutils.widgets.multiselect("foo", None, [None])
Exception raised:
Py4JJavaError: An error occurred while calling o427.createMultiselectWidget. : java.lang.NullPointerException at com.databricks.backend.daemon.driver.NotebookArguments.trimDefaultValue(NotebookArguments.scala:88)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2024 05:00 AM
The error you're encountering is due to trying to use None (or null in Java) as an option in the widget's default values or list of values, which dbutils.widgets.multiselect does not handle properly. The None type in Python is converted to null in Scala/Java (underlying languages in Spark), and this is causing a NullPointerException.
To fix this, you can provide a default value that is a non-null string instead of None. Here’s an example modification:
python
dbutils.widgets.multiselect("foo", "", ["Option1", "Option2"])
Alternatively, if you need the default to be unselected, you can set it to an empty list:
python
dbutils.widgets.multiselect("foo", "", ["Option1", "Option2"])
In this example, replacing None with actual strings will avoid triggering the NullPointerException. Let me know if this resolves the issue or if you need further assistance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2024 06:17 AM