简体   繁体   English

.jar文件将无法运行(InvocationTargetException)

[英].jar file won't run (InvocationTargetException)

I'm trying to setup FPSMeter app for UI performance test on Android device. 我正在尝试设置FPSMeter应用以在Android设备上进行UI性能测试。 They say I need to install both mobile and desktop parts of the app. 他们说我需要同时安装应用程序的移动部分和桌面部分。 There are no issues with the mobile part, but the .jar file of the desktop part doesn't launch. 移动部件没有问题,但是桌面部件的.jar文件没有启动。 I've tried launching it via command line, and that's what it returns: 我尝试通过命令行启动它,这就是返回的内容:

java -jar FPSMeterApp.jar
os windows
Exception in Application start method
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Lau
ncherImpl.java:389)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImp
l.java:323)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
        at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherIm
pl.java:917)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(
LauncherImpl.java:182)
        at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
        at application.Unpack.extract(Unknown Source)
        at application.Unpack.getFile(Unknown Source)
        at application.Unpack.file(Unknown Source)
        at application.ADB.<init>(Unknown Source)
        at application.Main.start(Unknown Source)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162
(LauncherImpl.java:863)
        at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(Platfor
mImpl.java:326)
        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(PlatformI
mpl.java:294)
        at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatch
er.java:95)
        at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.ja
va:191)
        ... 1 more
Exception running application application.Main

I have both x86 and x64 latest versions of Java RTE installed, I also tried to install them separately - nothing helps. 我同时安装了x86和x64最新版本的Java RTE,我也尝试单独安装它们-没有帮助。

I use Windows 7 (x64) under Admin role 我在管理员角色下使用Windows 7(x64)

Environment variables were set properly. 环境变量设置正确。

What should I do to actually launch it? 我应该怎么做才能真正启动它?

Ok, this is kind of strange solution (crude hack for sure) but can help you to solve the problem. 好的,这是一种奇怪的解决方案(肯定是粗暴的破解),但是可以帮助您解决问题。

First of all, from your stack trace here: 首先,从您的堆栈跟踪此处:

Caused by: java.lang.NullPointerException
        at application.Unpack.extract(Unknown Source)
        at application.Unpack.getFile(Unknown Source)
        at application.Unpack.file(Unknown Source)
        at application.ADB.<init>(Unknown Source)

... it looks like there is a NPE going on during initialization of some kind of adb wrapper (more precisely, during extraction of adb bundled within jar file). ……似乎在某种形式的adb包装程序初始化期间(更确切地说,在提取打包在jar文件中的adb期间)正在执行NPE。

This is pretty much all you can deduce from stack trace, so I downloaded jar, tried to run it and got exactly the same error (reproducible on Windows 8.1, jre7(32bit), jre8(32 and 64bit)). 您几乎可以从堆栈跟踪中推断出所有内容,因此我下载了jar,尝试运行它,并得到了完全相同的错误(在Windows 8.1,jre7(32位),jre8(32和64位)上可重现)。

I got curious and decided to poke it around with debugger\\decompiler. 我很好奇,决定用debugger \\ decompiler戳它。

Although it is hard to pinpoint exact reason why application.ADB misbehaves (due to specifics of how it was compiled) I've got an idea of fast and dirty trick you can use to avoid the problem. 尽管很难查明application.ADB行为不正确的确切原因(由于它的编译方式而异),但我有一个快速而肮脏的技巧可以用来避免该问题。 Namely, original application.ADB can be replaced with dummy stub and you may do adb unpacking manually. 也就是说,原始的application.ADB可以替换为虚拟存根,您可以手动执行adb解压缩。

Here is how to do it. 这是怎么做。

  1. unzip files adb.exe , AdbWinApi.dll , AdbWinUsbApi.dll located inside windows folder inside FPSMeterApp.jar 解压缩文件adb.exeAdbWinApi.dllAdbWinUsbApi.dll位于里面windows里面的文件夹FPSMeterApp.jar
  2. put them in the same directory as FPSMeterApp.jar 将它们与FPSMeterApp.jar放在同一目录中
  3. compile the following stub class ( javac ADB.java ): 编译以下存根类( javac ADB.java ):
package application;

public class ADB
{
  private String ADB_LOCATION = "adb.exe";

  ADB() {
  }

  public String getPath() {
    return this.ADB_LOCATION;
  }
}
  1. replace application/ADB.class inside FPSMeterApp.jar with ADB.class stub you just compilled 更换application/ADB.classFPSMeterApp.jarADB.class存根你只是compilled
  2. you can now run java -jar FPSMeterApp.jar 您现在可以运行java -jar FPSMeterApp.jar

These steps worked for me and I've been able to run jar without exceptions and see connected android devices in the UI. 这些步骤对我有用,并且我能够无例外地运行jar并在UI中查看已连接的android设备。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM