【发布时间】:2016-07-30 04:56:10
【问题描述】:
在 .jar 中部署我的游戏时,它在 Linux / Mac 上运行良好,没有错误。
但是在 Windows 上(目前专门测试 Windows 10),我在启动时遇到这些错误,然后在我的 JFrame 中出现一个空白屏幕:
Exception in thread "PooledThread7" java.lang.IllegalStateException: Buffers have not been created
at sun.awt.windows.WComponentPeer.getBackBuffer(Unknown Source)
at java.awt.Component$FlipBufferStrategy.getBackBuffer(Unknown Source)
at java.awt.Component$FlipBufferStrategy.flip(Unknown Source)
at java.awt.Component$FlipBufferStrategy.show(Unknown Source)
at engine.Game$Render.render(Game.java:250)
at engine.Game$Render.run(Game.java:167)
at engine.PooledThread.run(ThreadPool.java:89)
和
java.io.FileNotFoundException: res\maps\map.txt (The system cannot find the path specified)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileWriter.<init>(Unknown Source)
at engine.testMapCreator.init(testMapCreator.java:69)
at engine.Game.init(Game.java:126)
at engine.Game.main(Game.java:80)
所以看起来 Windows 不喜欢我的线程池渲染,并且由于某种原因,当它在 Linux 上找到 .jar 内的地图文件时,它在 Windows 上找不到它们。
...“一次编写,随处运行”就这么多,对吧?可能是什么问题?
编辑:这就是我阅读 map.txt 文件的方式:
InputStream is = Game.class.getResourceAsStream("/map.txt")
Scanner scanner = new Scanner(is);
(for loops to iterate over the data)
【问题讨论】:
-
错误不在读取,而是在写入到
res\maps\map.txt -
该部分已修复,但这是一个小问题。第一个问题是主要问题。到目前为止,我刚刚将渲染方法放在捕获 IllegalStateException 的尝试中,但是现在帧闪烁,同时在控制台中发送错误消息。似乎只有每隔几帧才能通过 try-catch 块。
标签: java linux windows multithreading jar