简体   繁体   中英

.jar file won't run (InvocationTargetException)

I'm trying to setup FPSMeter app for UI performance test on Android device. 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. 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.

I use Windows 7 (x64) under Admin role

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).

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)).

I got curious and decided to poke it around with 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. Namely, original application.ADB can be replaced with dummy stub and you may do adb unpacking manually.

Here is how to do it.

  1. unzip files adb.exe , AdbWinApi.dll , AdbWinUsbApi.dll located inside windows folder inside FPSMeterApp.jar
  2. put them in the same directory as FPSMeterApp.jar
  3. compile the following stub class ( 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
  2. you can now run 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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