我正在尝试切换到Sublime Text 3,但我遇到了一个问题。当我尝试使用Java包来组织我的代码时,linter会出现错误,我无法使用内置函数构建。这是代码:
Game.java:
package com.tatsu.main;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;
public class Game extends Canvas implements Runnable
{
private static final long serialVersionUID = 3582466025494978079L;
public static final int WIDTH = 640, HEIGHT = WIDTH / 12 * 9;
private Thread thread;
private boolean running = false;
public Game()
{
new Window(WIDTH, HEIGHT, "Game", this);
}
public synchronized void start()
{
thread = new Thread(this);
thread.start();
running = true;
}
public synchronized void stop()
{
try{
thread.join();
running = false;
}catch(Exception e){
e.printStackTrace();
}
}
public void run()
{
long lastTime = System.nanoTime();
double amountOfTicks = 60.0;
double ns = 1000000000 / amountOfTicks;
double delta = 0;
long timer = System.currentTimeMillis();
int frames = 0;
while(running)
{
long now = System.nanoTime();
delta += (now - lastTime) / ns;
lastTime = now;
while(delta >= 1)
{
tick();
delta--;
}
if(running)
render();
frames++;
if(System.currentTimeMillis() - timer > 1000)
{
timer += 1000;
System.out.println("FPS: " + frames);
frames = 0;
}
}
stop();
}
private void tick()
{
}
private void render()
{
BufferStrategy bs = this.getBufferStrategy();
if(bs == null)
{
this.createBufferStrategy(3);
return;
}
Graphics g = bs.getDrawGraphics();
g.setColor(Color.black);
g.fillRect(0, 0, WIDTH, HEIGHT);
g.dispose();
bs.show();
}
public static void main(String args[])
{
new Game();
}
}
Window.java:
package com.tatsu.main;
import java.awt.Canvas;
import java.awt.Component;
import java.awt.Dimension;
import javax.swing.JFrame;
public class Window extends Canvas
{
private static final long serialVersionUID = 420967586702448927L;
public Window(int width, int height, String title, Game game)
{
JFrame frame = new JFrame(title);
frame.setPreferredSize(new Dimension(width, height));
frame.setMaximumSize(new Dimension(width, height));
frame.setMinimumSize(new Dimension(width, height));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.add(game);
frame.setVisible(true);
game.start();
}
}
它显示新窗口(Game.java第18行)和Game游戏(Window.java第13行)的错误。然后它不会构建错误,说:
D:\Users\Tyler Miller\Documents\Java\Workspace\Game\src\com\tatsu\main\Game.java:18: error: cannot find symbol
new Window(WIDTH, HEIGHT, "Game", this);
^
symbol: class Window
location: class Game
1 error
[Finished in 0.5s with exit code 1]
我认为这是一个类路径错误,但我不知道如何解决它,我一直在谷歌搜索。非常感谢帮助:D
答案 0 :(得分:2)
如果其他人有兴趣解决Sublime-Linter类路径问题而不是使用Javatar:
args
配置中的SublimeLinter
设置允许您将类路径等参数传递给javac
。
例如,以下配置定义源文件编码,
包括两个图书馆lib/some_lib.jar
和lib/some_other_lib.jar
在类路径中,
并将src/
定义为项目的源路径:
"SublimeLinter": {
"linters": {
"javac": {
"lint": "all",
"args": [
"-encoding", "UTF8",
"-cp", "${project}/lib/some_lib.jar:${project}/lib/some_other_lib.jar",
"-sourcepath", "${project}/src/"
]
}
}
}
请注意,选项及其值必须是数组中的单独元素
(即"args": ["-sourcepath", "/path/to/src"]
确实有效
"args": ["-sourcepath /path/to/src"]
不起作用。)
答案 1 :(得分:0)
Javatar是一个非常好的选择。虽然没有真正的错误检查,但它可以很好地构建和运行。它也适用于w / linter对。我会认为这已经解决了。