在 .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)
最佳答案
对于第一个错误,可能在命令行中添加
-Dsun.java2d.d3d=false
会有所帮助(禁止使用 Direct3D 进行 2D 渲染)。例如:java -Dsun.java2d.d3d=false -jar some.jar
至于第二个,我们需要看看你是如何写文件的(提到了FileWriter),它可能是例如你没有
res\maps
目录。
关于java - 为什么我的游戏在 Linux 上运行良好,但在 Windows 上运行不正常? (Java.jar),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36507875/