Quinty
Quinty

Reputation: 199

How do I call an instance so I can test my method?

I have a class known as ImageProcessor which has a constructor called pic. Most of my functions have been defined for me in another class called pic.class. I want to add the red, green, and blue values of a pixel through my add method. When I attempt to call this method, I am getting an error that states "symbol not found". Given that I am unable to call it, how exactly do I create an instance correctly so I can call my add function appropriately.

/* Put your ImageProcessor class here */
import java.lang.String;
import java.lang.Math;
public class ImageProcessor {
    public String imageName;
    Pic p = new Pic(imageName);
    Pixel[][] picList = p.getPixels();
    int height = p.getHeight();
    int width = p.getWidth();
public static void main(String[] args){
        Pic current = new Pic("legoguy.png");
        Pixel[][] pics = current.getPixels();
        for(int a = 0; a < 1 ; a++) {
            int b = 0;
            Pixel p = pics[a][b];
            System.out.println(p.add(5));

        }
    }
//add function//
    public void add(int increment) {
        /////////////////////////////////////
        for(int x = 0 ; x < width - 1 ; x++){
            for(int y = 0; y < height - 1 ; y++){
                Pixel c = picList[x][y];
                int r = c.getRed();
                int g = c.getGreen();
                int b = c.getBlue();
                c.setRed(r + increment);
                checkPix(r + increment);
                c.setBlue(b + increment);
                checkPix(b + increment);
                c.setGreen(g + increment);
                checkPix(g + increment);
            }
        }
    }

Further Notes: checkPix just makes sure the values are between 0 and 255. The pic constructor follows this pattern: Pic(java.lang.String imageName). getRed/b/g are fuctions I defined in a pixel class that simply return the values, while setRed/b/g change those values.

Upvotes: -1

Views: 63

Answers (1)

monica
monica

Reputation: 512

I'm assuming that the add() method you included above is in your class Pic. You declared two different variables with the same name

Pic p = new Pic(imageName);
Pixel p = pics[a][b];

The compiler is giving you the error because it's not finding add() method in Pixel class

Upvotes: 0

Related Questions