...

View Full Version : Undefined Constructor Error



OnThe
04-29-2012, 05:40 PM
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. :)


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();
}
}


//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);
}

}


//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();
}
}

Fou-Lu
04-30-2012, 07:57 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum