当我调用我的两个方法时,我得到一个空指针异常。我不知道,为什么我得到它。当我检查代码时,它似乎是正确的
这是我的 HentbestillingsordreHandler 类
public class HentbestillingsordreHandler extends JPanel{
private Connection con = null;
private ResultSet rs = null;
private HentbestillingsordreRegistrer ho;
private ArrayList<HentbestillingsordreRegistrer> hbor = new ArrayList<HentbestillingsordreRegistrer>();
HentbestillingsordreHandler() {
}
public void Hentbestillingsordre(){
KaldSQL ks = new KaldSQL();
try {
con = ks.connectNow();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ResultSet rs = ks.Hentalleordreliste(con);
try {
while(rs.next()){
String status = "";
if(rs.getInt("BestillingsStatus") == 1){
status = "Leveret";
}else{
status = "Ikke Leveret";
}
System.out.println(status);
HentbestillingsordreRegistrer ho = new HentbestillingsordreRegistrer(
rs.getInt("BestillingsID"),
rs.getString("BestillingsStatus"),
rs.getInt("ModtagetAf"),
rs.getInt("Vare"),
rs.getInt("Antal"));
hbor.add(ho);
System.out.println(ho);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void printBestillingsordre(){
for(HentbestillingsordreRegistrer hentbestillingsordreRegistrer: hbor){
String temp = "";
temp += ho.getLeverandoerID()+" \n";
System.out.println(temp);
}
}
}
我的 kaldsql
public ResultSet Hentalleordreliste(Connection con){
ResultSet Hentalleordreliste = null;
try {
PreparedStatement statement = con.prepareStatement("select varebestillinger.BestillingsID, " +
"varebestillinger.LeverandoerID, "+
"varebestillinger.BestillingsStatus, varebestillinger.ModtagetAf, "+
"varebestillingsliste.Vare, " +
"varebestillingsliste.Antal from varebestillinger left outer join " +
"varebestillingsliste on ListeID = BestillingsID");
ResultSet result = statement.executeQuery();
Hentalleordreliste = result;
} catch (Exception e) {
e.printStackTrace();
}
return Hentalleordreliste;
}
这是我的班级 HentbestillingsordreRegistrer
int LeverandoerID;
String BestillingsStatus;
int ModtagetAf;
int Vare;
int Antal;
public HentbestillingsordreRegistrer(int LeverandoerID, String BestillingsStatus, int ModtagetAf,int Vare,int Antal){
this.LeverandoerID = LeverandoerID;
this.BestillingsStatus = BestillingsStatus;
this.ModtagetAf = ModtagetAf;
this.Antal = Antal;
}
public int getLeverandoerID() {
return LeverandoerID;
}
public void setLeverandoerID(int leverandoerID) {
LeverandoerID = leverandoerID;
}
public String getBestillingsStatus() {
return BestillingsStatus;
}
public void setBestillingsStatus(String bestillingsStatus) {
BestillingsStatus = bestillingsStatus;
}
public int getModtagetAf() {
return ModtagetAf;
}
public void setModtagetAf(int modtagetAf) {
ModtagetAf = modtagetAf;
}
public int getVare() {
return Vare;
}
public void setVare(int vare) {
Vare = vare;
}
public int getAntal() {
return Antal;
}
public void setAntal(int antal) {
Antal = antal;
}
当我调用它时,我输入这个
HentbestillingsordreHandler hboh = null;
hboh.Hentbestillingsordre();
hboh.printBestillingsordre();