我宣佈:新Java中獲得NullPointerException異常
Discursiva[] questoesDiscursivas = new Discursiva[10];
那就是:
public class Discursiva extends Questao{
private String criteriosCorrecao;
}
而且Questao是:
public class Questao {
private String pergunta;
private double peso;
}
所以我只是做:
str = JOptionPane.showInputDialog("Pergunta da Questao:");
questoesObjetivas[i].setPergunta(str);
得到了java.lang.NullPointerException。
我已閱讀oracle docs:在應用程序嘗試使用 null在需要對象的情況下拋出。這些措施包括:
Calling the instance method of a null object. Accessing or modifying the field of a null object. Taking the length of null as if it were an array. Accessing or modifying the slots of null as if it were an array. Throwing null as if it were a Throwable value.
而且我不知道爲什麼我收到NullPointerException
。 請不要低估我的問題,Iam仍在學習Java,它像我的第一個代碼一樣,我希望得到你的幫助,所以請,我該如何解決這個問題?
你在哪裏初始化'questoesObjetivas'? –
什麼是'questoesObjetivas',它有多大,拋出異常時'i'的值是多少? –
這將有助於查看所有您正在使用的代碼,或者至少setPergunta(String)函數中的代碼是什麼 –