首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Exception >

Jtree数据库出现java.lang.NullPointerException

2014-01-26 
------解决方法--------------------------------------------------------Node(资产) private JTree ge

------解决方法--------------------------------------------------------Node("资产");
private JTree getJTree() {
if (jTree == null) {
DefaultMutableTreeNode [] Node = null;
db.dbconn();
int i = 1;
String sql = "select * from channel where class=1";

try{
rs = db.stmt.executeQuery(sql);
while(rs.next()){
i++;
Node[i] = new DefaultMutableTreeNode(rs.getString("channel"));
root.add(Node[i]);
}
rs.close();
} catch(Exception e){e.printStackTrace();}
db.closedb();
jTree = new JTree(root);
jTree.setEditable(true);
treeModel = (DefaultTreeModel) jTree.getModel();
}
return jTree;
}

运行出现
java.lang.NullPointerException
at k.Property.getJTree(Property.java:139)

错误行 Node[i] = new DefaultMutableTreeNode(rs.getString("channel"));

------Jtree数据库出现java.lang.NullPointerException 解决方法--------------------------------------------------------
DefaultMutableTreeNode [] Node = null; 这句话不报NULL指针才怪,你可以用List