API适用于Java应用程序,但不适用于JavaFX [英] API works with Java application but not JavaFX

查看:242
本文介绍了API适用于Java应用程序,但不适用于JavaFX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Java和JavaFX构建软件。它生成PDF报告(使用DynamicReports),然后使用SendGrid API发送它们。我已经将SendGrid API .jar文件添加到类路径中。

I am building a software in Java and JavaFX. It generates PDF reports (with DynamicReports) then uses SendGrid API to send to send them. I have already added the SendGrid API .jar file to the classpath.

问题是当我实现我的SengGrid子类时,我的JavaFX应用程序崩溃了。如您所见:

The problem is that my JavaFX application crashes when I instanciate my subclass of SengGrid. As you can see:

Exception in thread "JavaFX Application Thread" java.lang.NoClassDefFoundError: com/sendgrid/SendGrid$Email
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:760)  at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at Reporting.TableReport.lambda$build$0(TableReport.java:160)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: com.sendgrid.SendGrid$Email
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 20 more

现在有趣的是,当我从非JavaFX项目调用API时,API工作正常。更有趣的是,当我从同一个JavaFX项目中的控制台主类中调用它时,它也可以工作。

Now the interesting part is that the API works perfectly when I call it from a non JavaFX project. And more interestingly, it also works when I call it from a "console" main class inside the very same JavaFX project.

到目前为止,我试图称之为控制台从我的JavaFX代码主要作为一种可以完成我的任务(发送PDF文件)的静态方法。但同样,我遇到了同样的例外。

So far, I have tried to call that "console" main from my JavaFX code as a sort of static method that would fulfill my task (sending the PDF files). But again, I encounter the very same exception.

有人可以提出解决方案来解决这个问题吗? (或者至少绕过它)

Can anyone suggest a solution to solve this ? (or at least go around it)

推荐答案

原来这是Netbeans的一个问题。在Eclipse中使用完全相同的代码可以完美地运行。我无法找到解释,但我会给那些可能偶然遇到与我同样的问题的人提供这个答案。

Turns out it was an issue with Netbeans. Using the exact same code with Eclipse works perfectly. I couldn't find an explanation but I'm giving this answer for anyone who might stumble upon the same issue as me.

这篇关于API适用于Java应用程序,但不适用于JavaFX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆