Search code examples
javastaticprivaterect

Java Grect And Private Static ERROR


This is code:

    package main;

import java.awt.*;
import acm.graphics.*;
import acm.program.*;

public class AjorBandi extends GraphicsProgram{

public void run(){
    private static final BRICK_TOOL=30 ;
    private static final BRICK_ARZ = 10;
    int x,y;
    x=0;
    y=100;
    for(int ii=0;ii<14;ii++){
    for(int i= 0;i<14;i++){
        Grect rect = new Grect(x,y,BRICK_TOOL,BRICK_ARZ);
        add(rect);
        x+=30;
        i-=1;       


    }
    y+=10;
    x+=15;


    }

}

}

This is Grect error messages from eclipse:

    Multiple markers at this line
- Grect cannot be resolved to a 
 type
- Grect cannot be resolved to a 
 type

This is private static error messages:

    Multiple markers at this line
- Line breakpoint:AjorBandi [line: 10] - run()
- Syntax error on token "final", float expected
- Illegal modifier for parameter BRICK_TOOL; only final is 
 permitted

I have compile error with this i eclipse IDE. What is the problem of this 2 errors?


Solution

  • Your two variables

    private static final BRICK_TOOL=30 ;
    private static final BRICK_ARZ = 10;
    

    have two problems.

    They should be declared at class level and you are missing the most important thing, the type. I give an example, where I use int for them:

    public class MyClass
    {
        private static final int BRICK_TOOL = 30;
        private static final int BRICK_ARZ = 10;
    
        myMethod()
        {
            //do stuff here
        {
    }