Skip to content

Basic Java Fundamentals

Attempting to call a method that’s in another object

public Shred(Path dir, int id){
        filename = dir.resolve(id+".png").toString();
        this.id = id;
    }

Using this loop

for (int i=0; i<count; i++){
            allShreds = allShreds + Shred(dir,i);
        }

However the Shred method is not able to be found using my code

Answer

That is a constructor not a method. And the constructor will return a Shred. It isn’t clear what allShreds is, but assuming it’s a String you could do

allShreds = allShreds + new Shed(dir,i).toString();