我想在類的頂部聲明變量,所以我不必在使用它們時經常聲明它們。我已經這樣做了,直到我想運行該程序時纔出現錯誤。我的代碼如下:如何解決 - java.lang.IllegalArgumentException:文本不能爲空或空
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
在運行時已經有文本,因此不確定爲什麼會發生此錯誤。
str在運行時沒有文本。你沒有初始化那個變量。 'String str;' – amicoderozer
你的例子不可執行。你在哪裏叫關鍵線?你能提供更多信息嗎? –