Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-29-2012, 04:40 PM   PM User | #1
OnThe
New to the CF scene

 
Join Date: Apr 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
OnThe is an unknown quantity at this point
Undefined Constructor Error

Hi there,

I'm new to programming. I'm trying to test code for a proxy/bridge design pattern. Whenever I compile, I get the error message: "The constructor RealImage() is undefined". I'm not sure if I should just simply create another constructor for RealImage() or if RealImage() needs to be tweaked in some way. I've included code for the test program and the implementer files. Thanks for taking the time to read this. I hope you help.

Code:
class Test  {

	public static void main(String[] args) {
		ImpToUse image1 = new ProxyImage("HiRes_10MB_Photo1");
		ImpToUse image2 = new ProxyImage("HiRes_10MB_Photo2");     

		image1.displayImage(); // loading necessary
		image1.displayImage(); // loading unnecessary
		image2.displayImage(); // loading necessary
		image2.displayImage(); // loading unnecessary
		image1.displayImage(); // loading unnecessary

		Image image3 = new JPegImage(new RealImage(), new ProxyImage());
		image3.Method();
	}	
}
Code:
//on System A 
class RealImage implements ImpToUse {
	private String filename;
  
	public RealImage(String filename) { 
		this.filename = filename;
		loadImageFromDisk();
	}

	private void loadImageFromDisk() {
		System.out.println("Loading   " + filename);
	}

	@Override
	public void displayImage() { 
		System.out.println("Displaying " + filename); 
	}

}
Code:
//on System B 
class ProxyImage implements ImpToUse {
	private String filename;
	private RealImage image;

	public ProxyImage(String filename) { 
		this.filename = filename; 
	}

	@Override
	public void displayImage() {
		if (image == null) {
			image = new RealImage(filename);
		} 
		image.displayImage();
	}
}
OnThe is offline   Reply With Quote
Old 04-30-2012, 06:57 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
The only constructors you have accept a filename. Either provide that filename during the instantiation of the objects, or add a default constructor that handles having no filename. Given what you have here, I'd suggest the filename is required.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:36 AM.


Advertisement
Log in to turn off these ads.