Hello!

I am having a bit of difficulty calling a function in my class Image. The point of the class is to generate a 2D array of Color instances, then do various things with it. Within my test code, my editor simply will not allow me to call any methods that are not fixed to static. Here is the problem class code (with constructor) and my test code. When I call "image.getPixel()" I get "Cannot invoke getPixel(int, int) on the array type Image[][]". Can someone give me a tip? Thanks so much!

Here is a part of my class code:

import java.awt.Color;

public class Image {
	
	/**This class encapsulates a 2D grid
	 * of pixels.**/
	
	Color image [][];
	int tester [][];
	int height;
	int width;
	
	/**This constructor takes two ints and
	 * produces a 2D array of white pixels **/
	public Image(int getHeight, int getWidth){
		height = getHeight;
		width = getWidth;
		//tester = new int[height][width];
		image = new Color [height][width];
		for(int i = 0; i < image.length; i++)
			for(int j = 0; j < image[0].length; j++)
				image[i][j]= Color.WHITE;

        /**This method returns the Color instance at
	 * pixel(column, row).**/
	public Color getPixel(int col, int row){
		Color color;
		color = image[col][row];
		return color;
	}

And my resulting test code:

import java.awt.Color;

public class ImageTester {
	
	public static void main(String[] args){
		
		Image image [][] = new Image[3][4];
               Color color = image.getPixel(0,0);
               System.out.println("This is the color at 0,0 "+ color);
}
}

I have no idea why it won't work! Please help you can~!

we don't call constructor like this,,,
change ur main method..

public static void main(String[] args){
	Image image = new Image(3,4);
	Color color = image.getPixel(0,0);
	System.out.println("This is the color at 0,0 "+ color);
	}

You are a doll vchandra! I just needed a fresh pair of eyes to see what my withered ones could not! Thanks so much!

we don't call constructor like this,,,
change ur main method..

public static void main(String[] args){
	Image image = new Image(3,4);
	Color color = image.getPixel(0,0);
	System.out.println("This is the color at 0,0 "+ color);
	}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.