Home > Enterprise >  java: bad operand types for binary operator '<'
java: bad operand types for binary operator '<'

Time:07-02

today guys i was doing some coding in java. i was creating a game following a tutorial. ut i found this error:

package net.mcreborn.fs;

import java.util.Random;

public class Render2 extends Render1
{
    public Render1 render;

    public void Render1()
    {
        render = new Render1();

        Random ra = new Random();
        for(int i = 0; i < render.pixels; i  )
        {
            render.pixels[i] = ra.nextInt();
        }
    }

    public void render()
    {
        draw(render, 0, 0);
    }
}

in for(int i = 0; i < render.pixels; i ) there is i(int) and render.pixels(int[]). But i see that i can't use '<'. so how i can change it? i can't change the variable type because it will give more errors.

that's the pixels variable declaration code:

package net.mcreborn.fs;

public class Render1
{
    public final int[] pixels;

CodePudding user response:

Change render.pixels to render.pixels.length.

By the way, you need to allocate the pixels property, otherwise you'll get a NullPointerException at runtime, as it is null by default.

  •  Tags:  
  • java
  • Related