aspose file tools*
The moose likes Beginning Java and the fly likes  Instantiate a new object inside a class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark " Instantiate a new object inside a class" Watch " Instantiate a new object inside a class" New topic
Author

Instantiate a new object inside a class

akash gall
Greenhorn

Joined: Feb 07, 2013
Posts: 3
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

Joined: Feb 06, 2012
Posts: 219

What do you have in MyClientManager class?
Show the whole code. and where is "this" reference used?


OCPJP
Ivan Jozsef Balazs
Rancher

Joined: May 22, 2012
Posts: 867
    
    5
Maybe the constructor in the very line throws an exception preventing the class from being initialized.



 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Instantiate a new object inside a class