Search code examples
javacsseclipsepixel

I have the error width cannot be resolved or is not a field (It's on the render.width at the end)


This is the error at the end(render.width)

pixels[xPix+yPix*width] = Render.pixels [x + y * render.width]; }

Here is the full code

package com.mime.WorldExplorer.graphics;

public class Render {
    public static int[] pixels;
    public final int width;
    public final int height;
    private int yOffset;
    private Object render;
    private int xPix;
    private int yPix;
    private int y;
    private int x;

    } 

    public void draw(Render render, int xOffset, int xoffset ) {
        for (int y = 0; y<render.height; y++); {
            int yPix = height + yOffset;
        }
    }
    {
            pixels[xPix+yPix*width] = Render.pixels [x + y * render.width]; 
    }
}

I'm not sure how to fix because I put it as a field


Solution

  • That line of code is outside the method - so it's render that's not being found.

    Additionally, you have a spurious ; in your for loop declaration:

    for (int y = 0; y<render.height; y++);
                                         ^--- You don't want this!
    

    It's not clear why you've got quite so many braces, but I suspect you actually want:

    // Note: I've changed the name of the third parameter from xoffset to yOffset
    public void draw(Render render, int xOffset, int yOffset) {
        for (int y = 0; y < render.height; y++) {
            int yPix = height + yOffset;
            pixels[xPix + yPix * width] = Render.pixels[x + y * render.width]; 
        }
    }
    

    It's not clear where you expect xPix to come from either - did you mean to use xOffset?