• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Instantiate a new object inside a class

 
akash gall
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

I have this requirement where I need to instantiate a new object inside a class (from a jar), its like a jdbc connection manager.

From a testMethod() (which is static) I am calling my class (which contains a reference to this object). The class looks like this:

public class myClient {

public static MyClientManager manager = new MyClientManager();

public static String validateConnection() {
return null;
}
}

From testMethod, I am going myClient.validateConnection() and its always failing. If I remove this line (public static MyClientManager manager = new MyClientManager()) it works.

Please help.
 
Ishan Pandya
Ranch Hand
Posts: 226
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you have in MyClientManager class?
Show the whole code. and where is "this" reference used?
 
Ivan Jozsef Balazs
Rancher
Posts: 981
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe the constructor in the very line throws an exception preventing the class from being initialized.



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic