• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static methods and nullpointerexceptions

 
Ravaa Bal
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,



I'm getting the error "non-static method connect cannot be referenced from a static context" in the main method, so I tried something like this:



This fixed that error, but then when ran I got this:

Exception in thread "main" java.lang.NullPointerException
at Connection.connecter(Connection.java:84)
at Connection.<init>(Connection.java:35)
at Connection.main(Connection.java:22)

Any insight on what I could be doing incorrectly would be welcome, thank you.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Connection.connect is somewhere you have somehow sent a null reference to something.
That has got there via Connection<init> which means the Connector constructor.
The line numbers don't seem to match the code you have supplied.

Most likely cause:
You have managed to pass something null to the Connection constructor. Make sure every argument you pass actually has an object attached to it.
 
Ravaa Bal
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yatta!

Thanks Campbell Ritchie, I did something silly and returned a null after a try catch block without having a return *inside* the try catch block.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome

Everybody does that sort of thing occasionally.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic