我正在尝试切换到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行)和游戏游戏(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
发布于 2016-03-15 07:33:52
如果其他人对解决Sublime-Linter类路径问题感兴趣,而不是使用Javatar:
SublimeLinter配置中的args设置允许您将类路径等参数传递给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"]不能工作)。
发布于 2016-02-19 14:02:57
Javatar是一个非常好的选择。虽然没有真正的错误检查,但它可以很好地构建和运行。它也适用于成对的w/ linter。我会认为这个问题已经解决了。
https://stackoverflow.com/questions/35474544
复制相似问题