我试图在类的顶部声明变量,这样我就不必在使用它们时不断地声明它们。我已经这样做了,直到我想运行程序才出现错误。我的代码如下:
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
不能为空或为空。我该如何解决这个问题?运行时str
已经有文本,所以不确定为什么会发生这个错误。