0

okay so how come i still get null pointer exception in this bit of code?

if (contact == null){
  contact = "default";
}else if (contact != null){
  accom.setContact(contact); //<--this line throws the null exeption
}

and this is run at the start to insure im connect to a database. i ran in debug mode as well and they are returning data from the database.

private void getConnection(){
    if(connection == null){
        try{
            Context initialContext = new InitialContext();
            //DataSource ds = (DataSource)initialContext.lookup(DATASOURCE_NAME);
            //connection = ds.getConnection();

            connection = DriverManager.getConnection("jdbc:derby://localhost:1527/Accomodation", "cqu", "cqu");
        }catch(NamingException e){
            e.printStackTrace();
        }catch(SQLException e){
            e.printStackTrace();
        }
    }
}

am i missing something really obvious?

theB
  • 6,450
  • 1
  • 28
  • 38
Daedric
  • 1
  • 6

0 Answers0