wood burning stoves 2.0*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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: 213

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: 865
    
    5
Maybe the constructor in the very line throws an exception preventing the class from being initialized.



 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Instantiate a new object inside a class
 
Similar Threads
does static methods inherit ? what about private ?
Problem with Junit control flow.
Protected Method
newbie's question about inner class existence
Instantiating Interface or Abstract