java.lang.NullPointerException异常,请问又什么解决方法?
点击右边红色标题查看本文完整版:java.lang.NullPointerException异常,请问又什么解决方法?
代码如下:
package factory;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import jdbc.Connect;
public class AssistFactory {
public static List <AssistEntity> getMatch() throws SQLException {
String sql = "select name,assist,t_name from statistics ";
Statement stmt = Connect.con.createStatement();
ResultSet rs = stmt.executeQuery(sql);
rs.beforeFirst();
// TODO 自动生成 catch 块
List <AssistEntity> list = new ArrayList <AssistEntity> ();
{
AssistEntity test = new AssistEntity();
test.setRank( "123 ");
test.setT_name( "123 ");
test.setName( "123 ");
list.add(test);
}
/*while(rs.next()){
AssistEntity assist = new AssistEntity();
assist.setName(rs.getString(2));
assist.setAssist(rs.getString(3));
assist.setT_name(rs.getString(4));
list.add(assist);
}*/
return list;
}
}
出错的是这句:Statement stmt = Connect.con.createStatement();
但是在别的类里同样的语句 正常运行
好几天了没解决
编译器错误提示:
java.lang.NullPointerException
at factory.AssistFactory.getMatch(AssistFactory.java:15)
at swt.MainWindow.createButton_7_Comp(MainWindow.java:787)
at swt.MainWindow.open(MainWindow.java:333)
at swt.MainWindow.main(MainWindow.java:87)
感谢 回复
------解决方法--------------------
空值错,Statement stmt = Connect.con.createStatement();
数据应该没连接上 con为NULL
------解决方法--------------------
应该是Connect类里的问题,你能把这个类贴出来么?
------解决方法--------------------
应该是数据库没连上