gpt4 book ai didi

java - 如何解决 - java.lang.IllegalArgumentException : text cannot be null or empty

转载 作者:行者123 更新时间:2023-11-30 02:43:38 25 4
gpt4 key购买 nike

我试图在类的顶部声明变量,这样我就不必在使用它们时不断地声明它们。我已经这样做了,所以在我想运行该程序之前不会出现错误。我的代码如下:

public class UI extends javax.swing.JFrame {

/**
* Creates new form UI
*/
public UI() {
initComponents();
this.service.setUsernameAndPassword("9a1d5de6-7c2b-427d-a574-d6fe097c86b9", "ztil6GSHwd34");
this.str = txtInput.getText();


}
String str;
PersonalityInsights service = new PersonalityInsights();
ArrayList<Double> percentagesList = new ArrayList();
Profile profile = service.getProfile(str).execute();
Gson gson = new Gson();
Root C = gson.fromJson(profile.toString(), Root.class);
Root.SubTree t = C.getSubTree(); //Gets subtree from root
ArrayList<Children> c = t.getChildren(); //Gets <Children> from Root.getSubTree

错误

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: text cannot be null or empty

我相信它是在说文本 str 不能为 null 或为空。我该如何解决这个问题?运行时 str 内部已包含文本,因此不确定为什么会发生此错误。

最佳答案

所以你有一个 UI 类,这里的所有变量都是数据成员......这里的问题似乎是 str 为空,因此你的服务正在提示。数据成员在构造函数之前初始化,因此在设置配置文件时,您的 str 为空。我会在类中声明成员并在构造函数中初始化它们,或者在第 6 行给 str 一个有效的初始值。

关于java - 如何解决 - java.lang.IllegalArgumentException : text cannot be null or empty,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40891082/

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