cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

NullpointerException when creating a notebook widget

sebasv
New Contributor II

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)
2 REPLIES 2

esther598
New Contributor III

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!

SathyaSDE
Contributor

Hi - pls see below

SathyaSDE_0-1729948623973.png

I hope it helps !!

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group