I'm new to java programming and I'm making a project which implies the use of java and mysql and I cannot manage to fix a NullPointerException in this piece of code, can anyone help me?
here's the full code, the connection part is working fine, its tested
package database;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import database.mainConnection;
public class userUtils extends mainConnection {
    public static void main(String[] args ) throws Exception {
        userLogin("mattia",hash("password");
    }
    /*public static Boolean registerUser(String name, String surname, String username, String email, String password, String Affiliation, String dateOfBirth) throws Exception {
        Connection con = getConnection();
        // 0000-00-00 format date
        PreparedStatement query = con.prepareStatement("INSERT INTO users (UserID, Username, Email, Password, Name, Surname, BirthDate, Affiliation) VALUES (?,?,?,?,?,?,?,?)");
        query.executeUpdate();
        return false;
    }*/
    public static Boolean userLogin(String username, String password) throws Exception {
        Boolean bool = null;
        try{
            Connection con = getConnection();
            PreparedStatement query = con.prepareStatement("SELECT * FROM users WHERE Username=? AND Password=?");
            query.setString(1, username);
            query.setString(2, password);
            ResultSet result = query.executeQuery();
            if(result.next()) {
                bool = true;
            }
            } catch(Exception e) {
                e.printStackTrace();
                }
        return bool;
    }
}
Also it doesn't give any results back, but i guess its due to the nullpointerexception
the error points at
con.prepareStatement("SELECT * FROM users WHERE Username=? AND Password=?"); and at a printlnine where i invoke the method
 
     
     
     
    