gpt4 book ai didi

java - Zip4j 库 ZipFile.setPassword() 方法在非空输入上抛出 NullPointerException

转载 作者:行者123 更新时间:2023-11-30 03:39:21 25 4
gpt4 key购买 nike

我正在循环缓冲读取器以从字典中提取行,将它们添加到 ArrayList,然后稍后在程序中运行它们。在这本 15,000,000 行的词典中,大约每 30,000 行就会出现一次空白行。我不希望该程序的所有用户都使用我包含的字典,并且我不想手动挑选并删除每个空白行。当程序遇到这一行时,它会抛出一个讨厌的 NullPointerException,立即终止程序。我尝试添加 try/catch 来添加该行(如果该行不为空),并使用 continue 传递空行。与往常一样,这是我的代码:

                String line;
if ((line = br.readLine()) != null) {
try{
passwordArray.add(line);
System.out.println(line);
} catch(NullPointerException npe){
System.out.println("The line is null.");
continue;
}
}

堆栈跟踪:

Exception in thread "main" java.lang.NullPointerException
at net.lingala.zip4j.core.ZipFile.setPassword(ZipFile.java:650)
at zZipCracker.zZipCracker.zZipCracker(zZipCracker.java:96)
at zZipCracker.zZipCracker.main(zZipCracker.java:55)

第 96 行:

zipper.setPassword((String) passwordArray.get(0));

查看第 96 行,正在添加空行,并且无法运行,因为我正在使用的库需要长度大于 0 的密码。第 55 行只是对完成整个过程的方法的调用。

最佳答案

问题可能是您的行是空的而不是空的。设置密码的代码如下:

648     public void setPassword(String password) throws ZipException {
649 if (!Zip4jUtil.isStringNotNullAndNotEmpty(password)) {
650 throw new NullPointerException();
651 }
652 setPassword(password.toCharArray());
653 }

您需要更改:

if ((line = br.readLine()) != null) {

至:

line = br.readLine();
if (line != null && line.length() > 0) {

关于java - Zip4j 库 ZipFile.setPassword() 方法在非空输入上抛出 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27137067/

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