此代码可以正常工作:
try {
sql = "SELECT * from profiles";
ResultSet res = stmt.executeQuery(sql);
while(res.next()) {
Profiles pProfile = new Profiles();
pProfile.setPersonalnummer(res.getInt(1));
pProfile.setAnwesenheit(res.getBoolean(2));
pProfile.setGrundDerAbwesenheit(res.getString(3));
pProfile.setRolle(res.getString(4));
pProfile.setWerk(res.getString(5));
pProfile.setMandant(res.getString(6));
pProfile.setFileName(res.getString(7));
allProfiles.add(pProfile);
}
} catch (SQLException e) {
e.printStackTrace();
}
return allProfiles;
以某种方式不起作用:
public List<Projects> getAllProjects() {
try {
sql = "SELECT * from projects";
ResultSet res = stmt.executeQuery(sql);
while(res.next()) {
Projects pProject = new Projects();
pProject.setProjektname(res.getString(1));
pProject.setProjektid(res.getInt(2));
allProjects.add(pProject);
}
} catch (SQLException e) {
e.printStackTrace();
}
return allProjects;
}
我只是复制粘贴了它,更改了值,但是使用“ getAllProjects()”方法时,以某种方式我得到了“ 500-内部服务器错误”。该错误消息表明执行“ allProjects.add(pProject)”时有一个空指针异常。也许有人可以帮我吗?提前致谢!
在方法顶部添加以下内容
List<Projects> allProjects = new Array<>();