- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
最近我尝试在 Eclipse 的 JavaFx Maven 项目中使用添加图片到标签。如果我在 Eclipse 中运行应用程序,一切正常,不会发生错误。
这篇文章不同于:“为什么相对路径在 JAR 文件中的 JAVA 中不起作用?”邮政!我尝试了这篇文章的解决方案,但对我没有用。我在下面对此进行了描述。
如果我从 Linux 终端运行应用程序,如 java -jar myapplication.jar
,则会出现以下错误:
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$412(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.FileNotFoundException: src/pictures/forms_logo_2_1.png (Datei oder Verzeichnis nicht gefunden)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:93)
at de.elastic.client.Main.pane1(Main.java:193)
at de.elastic.client.Main.start(Main.java:259)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$419(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$399(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$397(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$398(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication.lambda$null$203(GtkApplication.java:139)
... 1 more
Exception running application de.elastic.client.Main
我在图片的文件导入中定位了错误。对于导入,我使用了这段代码:
FileInputStream input = new FileInputStream("path/picture.png");
Image image = new Image(input);
Label img1 = new Label();
img1.setGraphic(new ImageView(image));
我还尝试将 imageUrl 直接提供给 Image 类,如 Image image = new Image(imageUrl);
。这在我以前的项目中有效。
我也试过 Image image = new Image(getClass().getResourceAsStream(imageUrl));
但这里 eclipse 抛出错误 Cannot make a static reference to the non-static method getClass () 来自对象类型
。
关于这一点,我还尝试了 Image image = new Image(Main.class.getResource(imageUrl).toExternalForm();
。对我来说,它只能以这种方式执行而不会出错。
更新:我也试过这个:
ClassLoader classLoader1 = Main.class.getClassLoader();
String ImgUrl1 = classLoader1.getResource("path/picture.png").toExternalForm();
Image image = new Image(ImgUrl1);
Label img1 = new Label();
img1.setGraphic(new ImageView(image));
它抛出与上面相同的错误。
更新: 好吧,似乎可执行 JAR 文件本身不匹配,无法找到图片和其他数据。因此,例如图片位于图片文件夹中,应用程序无法在图片文件夹中找到它。所以是引用问题。 因为我把它转成了maven工程,可能是结构不对。我将尝试创建一个新的 maven 项目并将结果发布在这里。
因为这是我发现的将图片导入标签的所有常用方法,所以我有点沮丧。我希望有人能解决这个小问题。干杯!
最佳答案
我自己找到了解决办法。 maven项目的文件系统和代码的排列有问题。错误发生在[右键单击] > configure > convert to maven project
中使用eclipse特性。这导致程序的文件系统中缺少一些文件夹。现在可以简单地引用文件。
解决方案是创建一个新的 Maven 项目并从旧项目中迁移所有内容。比它对我有用。干杯!
关于转换后的 Maven 项目中文件的 JavaFx InvocationTargetException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54361848/
我遇到的问题是:我有一系列通过注释收集的类。它们都位于同一个文件夹中,如果它们具有特定的注释,它们将通过 Reflections library 实例化。 。当这些类被实例化时,有一个静态初始化程序调
我一直试图了解问题到底是什么,但无论我做什么似乎都不起作用。我有一个文本文件,其中列出了名称和数字,并用冒号分隔。一个例子是: Betty Ross:52 Angie Scotts:29 Michae
我这里有一个小问题,希望有人能帮助我。 我想做一个从对象到整数的映射。该对象被标记为 Fetchtype.Lazy。 当我进行映射时,我收到以下错误消息: 11:31:46,569 ERROR Map
JUnitTest/Mockito/PowerMockito:: 尝试从 android 中的 res/raw 文件访问数据集 json 文件,但出现“InvocationTargetExceptio
我正在开发一个项目,该项目将包含许多具有相似但不同功能的 JavaFX 应用程序,因此我创建了一个抽象基类,它扩展了 Application 以处理通用功能并指示它们需要做什么,以及一个一堆扩展那个的
我有一个复杂的结构要显示在屏幕上。使用 XML 布局制作。对于垂直方向和纵向布局是不同的。 如果您翻转屏幕布局,则会重新绘制并初始化 GUI。在水平布局上,我使用 CustomRelativeLayo
我正在尝试基于 Zentask 示例创建一个简单的登录,但是在第 43 行的 smgts2\app\controllers\Application.java 中出现运行时异常。 public stat
我正在尝试将我的所有 java 应用程序升级到 openJDK11(来自 Oracle 8)。 我注意到我的报告服务器中使用 Pentaho 的一个问题。 看来 Excel 自动调整大小功能需要 op
我正在尝试将 hive 与蜂路线或色相连接,因此我遇到了错误 2015-01-01 11:56:18,312 ERROR sentry.org.apache.thrift.transport.TSas
我在页面中使用框架从服务器获取一些数据。 加载页面后,我注意到有两个调用传递给服务器: 一个在src框架中定义的NB_tans操作中的一个,另一个在页面中任何位置定义的tans操作中的另一个。 HTM
我无法在Kotlin-test 3.4.2中使用Koin 2.0.1。我得到这样的InvocationTargetException: Running koinexample.KoinSampleTe
我正在尝试添加 Hibernate 5 作为后端的 ORM 以连接 MySQL 数据库。我阅读了许多示例和教程,但总是收到 InvocationTargetException。 下面是相关代码。希望有
我正在尝试为 Android 设备上的 UI 性能测试设置 FPSMeter 应用程序。 They say我需要安装应用程序的移动和桌面部分。移动部分没有问题,但桌面部分的 .jar 文件无法启动。我
ActivityManager am = (ActivityManager)this.getSystemService(this.ACTIVITY_SERVICE); try { clear
我目前在 Android 开发者控制台上收到一些未知的崩溃报告。他们很不善于表达。它是一个 InvocationTargetException,但我不知道它来自哪里。也许我正在使用的某些框架正在使用反
我正在写一个状态检查器,它是一个 java web-start 小程序。我可以在我的电脑上运行它,但是它运行得很好;当我在网页上运行它时,出现运行时错误 java.lang.reflect.Invoc
我在OPPO X905和OPPO X907上遇到过问题,都是Android 4.0.3(API Level 15),我没有用过更高级别的API,我在Google和SO上搜索过,都是不一样的根据我的问题
如何重新抛出 InvocationTargetException 的目标异常。我有一个方法,它使用反射在我的一个类中调用 invoke() 方法。但是,如果在我的代码中抛出异常,我不关心 Invoca
根据 javadocs , InvocationTargetException.getCause() 可以为空: Returns the cause of this exception (the th
我有一个使用 AsyncTask 的简单 Activity EditText txt; @Override public void onCreate(Bundle savedInstanceState
我是一名优秀的程序员,十分优秀!