0

This code works completely fine:

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; 

Somehow this doesn't work:

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; 

}

I just copy-pasted it, changed the values, but somehow i get a "500 - Internal Server Error" when using the "getAllProjects()" method. The error message says that there is a Null Pointer Exception when executing "allProjects.add(pProject)". Maybe somebody can help me? Thanks in advance!

Quantum
  • 17
  • 1
  • 1
  • 5
  • 1
    Show the entire exception please. – Jason Mar 26 '20 at 20:24
  • I don't see the stmp object being created so that is a possibility. You need to show the entire code or at least all relevant code. Also, usually Statement/PrepareStatement/ResultSet are closed after usage but you don't seem to be doingthat as well. – Jason Mar 26 '20 at 20:25
  • Where is ```allProjects``` initialized? Cannot see in your code. – Sanil Mar 26 '20 at 20:27

1 Answers1

-1

add below at top of your method

List<Projects> allProjects = new Array<>();
Ben
  • 54
  • 4