gpt4 book ai didi

java - 从 Excel 中读取空白值并在脚本中使用它

转载 作者:行者123 更新时间:2023-12-01 11:22:56 27 4
gpt4 key购买 nike

我正在执行以下步骤:

  1. 从 Excel 读取值。
  2. 从 Excel 读取字段中的值后传递该值。

(假设我的 Excel 工作表的 A1 值为“TestUserName”,我将其传递到用户名字段中。)

但目前如果单元格值为空,则会抛出nullPointerException。该如何进行呢?

在这种情况下假设如果我的 A1 值为空如何处理这种情况。我没有使用arralist。

最佳答案

为什么不捕获 NullPointerException 并将其替换为空字符串?

例如:

string username ;
try
{
//Your code that fetches Excel cells contents
username = fetchCell("A1"); //here it throws the exception if the cell is empty
}
catch(NullPointerException e)
{
username = "";
}

关于java - 从 Excel 中读取空白值并在脚本中使用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31043198/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com