【问题标题】:Java Grect And Private Static ERRORJava Grect 和私有静态错误
【发布时间】:2014-11-12 17:02:49
【问题描述】:

这是代码:

    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;


    }

}

}

这是来自 eclipse 的 Grect 错误消息:

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

这是private static 错误信息:

    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 eclipse IDE 出现编译错误。 这2个错误是什么问题?

【问题讨论】:

  • Java 区分大小写。这是GRect

标签: java static private rect


【解决方案1】:

你的两个变量

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

有两个问题。

它们应该在类级别声明,而您缺少最重要的东西,类型。 我举个例子,我为他们使用int

public class MyClass
{
    private static final int BRICK_TOOL = 30;
    private static final int BRICK_ARZ = 10;

    myMethod()
    {
        //do stuff here
    {
}

【讨论】:

  • 令牌“final”的语法错误,当我将它放入类和方法外时预期会浮动
  • 那是因为你还没有为变量设置一个type。 Java 是一种type-safe 语言。
  • 如果对您有帮助,请考虑回复并接受答案。
猜你喜欢
  • 2013-12-17
  • 2020-11-12
  • 2011-09-04
  • 2017-02-25
  • 2011-03-04
  • 2022-11-20
  • 1970-01-01
  • 1970-01-01
  • 2014-06-08
相关资源
最近更新 更多