Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •