【发布时间】:2016-11-30 14:36:45
【问题描述】:
我试图在类的顶部声明变量,这样我就不必在使用它们时不断地声明它们。我已经这样做了,直到我想运行程序才出现错误。我的代码如下:
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 在运行时已经有文本,所以不确定为什么会发生这个错误。
【问题讨论】:
-
str 运行时没有文本。您没有初始化该变量。
String str; -
您的示例不可执行。你把临界线叫做哪里?你能提供更多信息吗?
标签: java user-interface personality-insights