首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Robocode上的java中解决"the Syntax error,static imports are available java level is is 1.5或更高“

如何在Robocode上的java中解决"the Syntax error,static imports are available java level is is 1.5或更高“
EN

Stack Overflow用户
提问于 2018-10-15 05:38:56
回答 3查看 1.7K关注 0票数 1

我试图在机器人代码上编译机器人,但它说“静态导入只有在源代码级别为1.5或更高时才可用”。

我不明白这是什么意思。我在其他论坛上看到可以更新Java,但我的电脑上已经安装了最新的Java。我能做什么?

这是我试图编译的代码:

代码语言:javascript
复制
package blir.dev; 

import robocode.*;

import java.awt.Color;

import static robocode.util.Utils.*; 

/** 
* Blixi - a robot by Travis Bruce 
*/
public class Keen_Stalker extends AdvancedRobot { 

//the direction we're moving 
private int dir = 1; 
//are we close to a wall? : are we close to a robot?
private boolean wall = false, rbt = false; 
//enemy's energy 
private double en = 100D; 

/** 
 * run: Blixi's default behavior 
 */
public void run() { 
    setColors(Color.BLACK, Color.DARK_GRAY, Color.DARK_GRAY); 
    setAdjustRadarForRobotTurn(true); 
    setAdjustGunForRobotTurn(true); 
    setAdjustRadarForGunTurn(true); 
    //if (bshot1 != 0) out.println("Main Gun Accuracy: " + (double) bhit1 / bshot1);
    for (;;) { 
        if (getRadarTurnRemaining() == 0) { 
            //should only happen if we lose track of them, which should never happen 
            setTurnRadarRight(Double.POSITIVE_INFINITY); 
        } 
        //check if we're too close to the wall (50 pixels) 
        wall = cw(50, true); 
        execute(); 
    } 
} 

/** 
 * onScannedRobot: What to do when you see another robot 
 */
public void onScannedRobot(ScannedRobotEvent e) { 

    //check if we're too close to the other robot (150 pixels) 
    rbt = d(e.getDistance()); 

    //absolute bearing
    double absBear = getHeadingRadians() + e.getBearingRadians(); 

    //track them with our radar 
    double radarTurn = normalRelativeAngle(absBear - getRadarHeadingRadians()); 
    radarTurn += (radarTurn < 0 ? -1 : 1) * Math.atan(36.0 / e.getDistance()); 
    setTurnRadarRightRadians(radarTurn); 

    //fire power the enemy used
    double enemyPower = en - e.getEnergy();

    if (enemyPower <= 3 && enemyPower > 0 && !cw(75, false)) { 
        //they seem to have fired
        cd(); 
    } 

    //record new energy 
    en = e.getEnergy(); 

    //circle around them if we're close enough, move away if we're too close
    setTurnRightRadians(normalRelativeAngle(e.getBearingRadians() + Math.PI / 2D)); 

    setTurnGunRightRadians(normalRelativeAngle(absBear - getGunHeadingRadians() -
            Math.asin(e.getVelocity() * Math.sin(Math.PI - absBear + e.getHeadingRadians()) / Rules.getBulletSpeed(Rules.MAX_BULLET_POWER)))); 

    //fire! 
    setFire(Rules.MAX_BULLET_POWER); 

    //all power ahead! 
    setAhead(dir * 32);
} 

public void onHitWall(HitWallEvent e) { 
    //out.println("Ahh! A wall!"); 
    cd(); 
}  

private boolean d(double d) { 
    if (d < 150) { 
        //we're close to the robot (within 150 pixels) 
        if (!rbt) { 
            //we're not already escaping the robot, so let's change direction 
            cd(); 
        } 
        return true; 
    } 
    return false; 
} 

private boolean cw(int d, boolean cw) { 
    if (getX() < d || getY() < d || getBattleFieldWidth() - getX() < d || getBattleFieldHeight() - getY() < d) { 
        //we're close to the wall 
        if (!wall && cw) { 
            //we're not already escaping the wall, so let's change direction 
            cd(); 
        } 
        return true; 
    } 
    return false; 
} 

private void cd() { 
    dir = -dir; 
}                                                                                          
EN

回答 3

Stack Overflow用户

发布于 2018-10-15 06:33:15

一个快速的解决办法是删除import static robocode.util.Utils.* (构造导入静态是在Java1.5中引入的,请参阅此处:https://docs.oracle.com/javase/1.5.0/docs/guide/language/static-import.html),并使用Utils.normalRelativeAngle等。

一个合适的修复方法是找出为什么将源代码级别设置为小于1.5的原因

票数 1
EN

Stack Overflow用户

发布于 2018-10-15 05:54:43

我不确定你是否检查了其他答案,但请检查下面的链接。

eclipse magic: ... Syntax error, varargs are only available if source level is 1.5 or greater

有很多你可以尝试的东西。

希望这能有所帮助。

票数 0
EN

Stack Overflow用户

发布于 2019-07-16 19:38:12

在Robocode编译器选项中添加以下注释:-source 1.5

->Compiler选项[-deprecation -g -source 1.5 -encoding UTF-8]

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52807332

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档