日期:2014-05-20  浏览次数:20819 次

空指针异常求大侠解惑,小弟不胜感激
空指针异常 弄了好久也没明白到底是出问题了,重点是抛出错误但是没提示具体是哪里出错了
        inquire3 = new JPanel(new BorderLayout());
String[] title3 = {"顾客姓名","身份证号","手机号码"};
Object[][] datas3 = DataGained.getInstance().getGuestVipYes();
table3 = new JTable(datas3,title3);//在这一句抛出空指针异常
int columncount3 = table3.getColumnCount();
for(int i=1;i<columncount3;i++){
table3.getColumnModel().getColumn(i).setPreferredWidth(50);
}
table3.setRowHeight(25);
inquire3.add(table3.getTableHeader(),BorderLayout.NORTH);
inquire3.add(table3,BorderLayout.CENTER);



                public Object[][] getGuestVipYes(){
return selectGuestVipYes(" select  * from hm_guest where isVIP = 'YES' ");
}




protected Object[][] selectGuestVipYes(String sql){
Object[][] obj1 ={};
Connection dbConn = DataLinked.getConnection();
try{
Statement stmt = dbConn.createStatement();
ResultSet rs = stmt.executeQuery(" select count(*) from hm_guest where isVIP = 'YES' ");
int row = 0;
if(rs.next()){
row = rs.getInt(1);
}
rs = stmt.executeQuery(sql);
for(int i=0;i<row;i++){
obj1 = new Object[row][];
while(rs.next()){
obj1[i] = new Object[3];
for(int j=0;j<3;j++){
obj1[i][j] = rs.getObject(j+2);
}
}
}
rs.close();
stmt.close();
}catch(SQLException e){
e.printStackTrace();
}
return obj1;
}






Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.JTable$1.getValueAt(Unknown Source)
at javax.swing.JTable.getValueAt(Unknown Source)
at javax.swing.JTable.prepareRenderer(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source)
at javax.swing.plaf.ComponentUI.update(Unknown Source)
at javax.swing.JComponent.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JViewport.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JSplitPane.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)