如何导出带有proccessing(Eclipse)的可运行的罐子
我试图将处理小程序从Eclipse(我用来代码编码)导出到可运行的JAR文件中,并且它成功导出,但是当打开时,只会导致空白(灰色)屏幕。如果我使用命令提示符运行它,我会收到此错误:
java.lang.nullpointerexception:无法调用“ string.contains(java.lang.charequence)”,因为
当我提取jar示例文件夹和目录时, “ jarpath”是无效的也不正确。
我确定它是在生成上的文件结构的问题,更具体地说是依赖项。当我作为应用程序日食运行时,它运行得很好,没有例外。
完整消息:
java.lang.lang.nullpointerexception:无法调用“ string.contains(java.lang.charsequence)”,因为“ jarpath”为null 在processing.core.papplet.datafile(papplet.java:7673) 在processing.core.papplet.datapath(papplet.java:7650) 在processing.core.papplet.createinputraw(papplet.java:6741) 在processing.core.papplet.createinput(papplet.java:6659) 在processing.core.papplet.loadbytes(papplet.java:6959) 在processing.awt.shimawt.loadimage(shimawt.java:384) at processing.core.psurfacenone.loadimage(psurfacenone.java:61) 在processing.core.papplet.loadimage(papplet.java:5311) 在processing.core.papplet.loadimage(papplet.java:5296) 在net.turke1034.shootergame.game.game.shootergame.draw(shootergame.java:55) 在processing.core.papplet.handledraw(papplet.java:2201) 在processing.awt.psurfaceawt $ 10.calldraw(psurfaceawt.java:1422) 在processing.core.psurfacenone $ andimationThread.run(psurfacenone.java:354) java.lang.nullpointerexception:无法调用“ string.contains(java.lang.charequence)”,因为“ jarpath”为null 在processing.core.papplet.datafile(papplet.java:7673) 在processing.core.papplet.datapath(papplet.java:7650) 在processing.core.papplet.createinputraw(papplet.java:6741) 在processing.core.papplet.createinput(papplet.java:6659) 在processing.awt.shimawt.loadimageio(shimawt.java:454) 在processing.awt.shimawt.loadimage(shimawt.java:439) at processing.core.psurfacenone.loadimage(psurfacenone.java:61) 在processing.core.papplet.loadimage(papplet.java:5311) 在processing.core.papplet.loadimage(papplet.java:5296) 在net.turke1034.shootergame.game.game.shootergame.draw(shootergame.java:55) 在processing.core.papplet.handledraw(papplet.java:2201) 在processing.awt.psurfaceawt $ 10.calldraw(psurfaceawt.java:1422) 在processing.core.core.psurfacenone $ andimationThread.run(psurfacenone.java:354)
我在一个不需要依赖项的测试项目中尝试了同一件事,并且它按预期运行(在命令提示中运行时)
I have tried to export my processing applet to a runnable jar file from eclipse (which I am using to code it) and it exports successfully but when opened just causes a blank (grey) screen. If I run it with command prompt I get this error:
java.lang.NullPointerException: Cannot invoke "String.contains(java.lang.CharSequence)" because "jarPath" is null
When I extracted the jar sample the folders and directories seem to be incorrect too.
before
(the dependencies are in the dependencies folder)
after
(the dependencies are outside of the now missing dependencies folder)
I'm sure its an issue with the file structuring on generation, more specifically the dependencies. when I run it as an application eclipse it runs perfectly fine with no exceptions.
Full message:
java.lang.NullPointerException: Cannot invoke "String.contains(java.lang.CharSequence)" because "jarPath" is null at processing.core.PApplet.dataFile(PApplet.java:7673) at processing.core.PApplet.dataPath(PApplet.java:7650) at processing.core.PApplet.createInputRaw(PApplet.java:6741) at processing.core.PApplet.createInput(PApplet.java:6659) at processing.core.PApplet.loadBytes(PApplet.java:6959) at processing.awt.ShimAWT.loadImage(ShimAWT.java:384) at processing.core.PSurfaceNone.loadImage(PSurfaceNone.java:61) at processing.core.PApplet.loadImage(PApplet.java:5311) at processing.core.PApplet.loadImage(PApplet.java:5296) at net.turke1034.shootergame.game.ShooterGame.draw(ShooterGame.java:55) at processing.core.PApplet.handleDraw(PApplet.java:2201) at processing.awt.PSurfaceAWT$10.callDraw(PSurfaceAWT.java:1422) at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:354) java.lang.NullPointerException: Cannot invoke "String.contains(java.lang.CharSequence)" because "jarPath" is null at processing.core.PApplet.dataFile(PApplet.java:7673) at processing.core.PApplet.dataPath(PApplet.java:7650) at processing.core.PApplet.createInputRaw(PApplet.java:6741) at processing.core.PApplet.createInput(PApplet.java:6659) at processing.awt.ShimAWT.loadImageIO(ShimAWT.java:454) at processing.awt.ShimAWT.loadImage(ShimAWT.java:439) at processing.core.PSurfaceNone.loadImage(PSurfaceNone.java:61) at processing.core.PApplet.loadImage(PApplet.java:5311) at processing.core.PApplet.loadImage(PApplet.java:5296) at net.turke1034.shootergame.game.ShooterGame.draw(ShooterGame.java:55) at processing.core.PApplet.handleDraw(PApplet.java:2201) at processing.awt.PSurfaceAWT$10.callDraw(PSurfaceAWT.java:1422) at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:354)
I have tried the same thing with a test project that requires no dependencies, and it runs as expected (when run in command prompt)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
遇到了同样的问题,因此进行故障排除了一段时间,直到我找到以下解决方案。我假设您在处理项目中使用类似于数据文件的数据文件来控制您的依赖项。
在Eclipse中,作为可运行的jar导出,然后选择“提取必需的库中所需的库中生成的jar”。创建罐子后,将此罐子放入新文件夹中。还将数据文件夹也放入此文件夹中。这对我有用。
不知道为什么会起作用 - 只是把东西放在墙上,直到卡住为止。我使用的一种故障排除技术是在加载任何数据之前先制作打印词,以便我可以看到计算机在哪里搜索依赖项。下面的摘要将文件输出到处理数据的同一位置。
我将其与DataPath(“”)结合使用,发现它正在寻找罐子外的依赖项。
had the same issue, so troubleshooted for a while until i found the following solution. i'm assuming that you are using a data file similar to the data file in Processing projects to contain your dependencies.
in Eclipse, export as a runnable jar and select the option "Extract required libraries into generated JAR". once the jar is created, put this jar into a new folder. put your data folder into this folder as well. this worked for me.
no idea why this works - just threw stuff at the wall until this stuck. one troubleshooting technique i used was making a printwriter before loading any data so i could see where the computer was searching for the dependencies. the snippet below outputs the file to the same place that Processing looks for data.
i used this in combination with dataPath("") to find that it was looking for dependencies outside of the jar.
过去( /a>)我成功地将可运行的.jar项目导出了Eclipse,这些项目通过使用复制所需的库将所需的库中的子文件库中的选项旁边的子文件库中的 运行jar jar files export的子折叠列出来使用。选项:
这使得更容易调试Java class class pathS essport(
-cp
flaf ins command在命令中运行时线路)和本机库路径(-d.java.library.path
命令行标志)。如果您使用的是Java软件包,请记住在
papplet.main()
中指定它们:以上仅在由于缺少库而无法执行JAR文件时才有用库等)
关于加载外部资产,如Shivoum B所述,您可以使用
datapath()
,但也 sketchpath()。 /54000598/error-message-the-file-countries-geo-json-is-missing-missing-missing-cossible/54048109#54048109“>此类似的答案)。我只能做出假设,但是您可以在shootergame.java中逃脱这样的东西
没有看到
loadImage()
调用的路径, 我正确阅读了这篇文章,您正在尝试将图像加载在draw()
中?我建议在
setup()
中加载所有资产一次,而不是draw()
中的多次。一种特殊情况可能是加载大量资产,这些资产需要时间并使用p2d
或p3D
p3D 其中OpenGL上下文设置可能会超时(您可以在其中加载> draw()
,但应使用“辩论”布尔值来确保仅加载资产一次)In the past (older answer here) I had success exporting runnable .jar projects from eclipse which use Processing's libraries by using the Copy required libraries into a sub-folder next to the generated jar option in Runnable Jar File Export options:
This made it easier to debug java classpath issues (
-cp
flag when running from command line) and native library paths(-D.java.library.path
command line flag).If you're using java packages remember to specify them in
PApplet.main()
:The above is useful only if you can't execute the jar files due to missing libraries (class not found, missing native libraries, etc.)
Regarding loading external assets, as Shivoum B mentions, you can make use of
dataPath()
but also sketchPath().(See this similar answer).Without seeing the path to the
loadImage()
call you're making I can only make assumptions, but you might be able to get away with something like this in ShooterGame.java:(Off-topic, if I read this correctly you're trying to load images in
draw()
?I'd recommend loading all assets in
setup()
once instead of multiple times indraw()
. A special case might be with the loading large assets that take time and usingP2D
orP3D
where the OpenGL context setup might time out (in which you can load indraw()
but should use a "debouncing" boolean to ensure assets are loaded only once)