Eclipse Plugin: If Annotation is not present, AbstractAnnotationHover results in a NullPointerException - java

What i have: I develop an Eclipse editor and override the getTextHover Method in the SourceViewerConfiguration with this method:
public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
return new AbstractAnnotationHover(true) {
public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) {
IAnnotationModel model = ((SourceViewer) textViewer).getAnnotationModel();
#SuppressWarnings("unchecked")
Iterator<Annotation> parent =
((IAnnotationModelExtension2)model).getAnnotationIterator(hoverRegion.getOffset(),
hoverRegion.getLength(), true, true);
Iterator<?> iter = new JavaAnnotationIterator(parent, false);
Annotation annotation = null;
Position position = null;
while (iter.hasNext()) {
Annotation a = (Annotation) iter.next();
Position p = model.getPosition(a);
annotation = a;
position = p;
}
return new AnnotationInfo(annotation, position, textViewer) {
public ICompletionProposal[] getCompletionProposals() {
ICompletionProposal proposal1 = null;
IMarkerResolution [] resolutions = null;
ICompletionProposal [] com = null;
if (annotation instanceof MarkerAnnotation) {
resolutions = new ErrorResolution().getResolutions(((MarkerAnnotation) annotation).getMarker());
if(resolutions.length != 0){
proposal1 = new MarkerResolutionProposal(resolutions[0],
((MarkerAnnotation) annotation).getMarker());
return new ICompletionProposal[] { proposal1 };
}
}
return com ;
}
};
}
};
}
It displays QuickFixes when hovering over an annotated error in the code viewer. But if i hover over an error, which has no quick fix or just a correct line of code, it results in the following error:
org.eclipse.swt.SWTException: Failed to execute runnable (java.lang.NullPointerException)
at org.eclipse.swt.SWT.error(SWT.java:4491)
at org.eclipse.swt.SWT.error(SWT.java:4406)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:138)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4155)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3772)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:694)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:606)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:139)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
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:497)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608)
at org.eclipse.equinox.launcher.Main.run(Main.java:1515)
at org.eclipse.equinox.launcher.Main.main(Main.java:1488)
Caused by: java.lang.NullPointerException
at org.eclipse.jdt.internal.ui.text.java.hover.AbstractAnnotationHover$AnnotationInformationControl.createAnnotationInformation(AbstractAnnotationHover.java:329)
at org.eclipse.jdt.internal.ui.text.java.hover.AbstractAnnotationHover$AnnotationInformationControl.deferredCreateContent(AbstractAnnotationHover.java:282)
at org.eclipse.jdt.internal.ui.text.java.hover.AbstractAnnotationHover$AnnotationInformationControl.setInput(AbstractAnnotationHover.java:186)
at org.eclipse.jface.text.AbstractInformationControlManager.internalShowInformationControl(AbstractInformationControlManager.java:1181)
at org.eclipse.jface.text.AbstractInformationControlManager.presentInformation(AbstractInformationControlManager.java:1150)
at org.eclipse.jface.text.AbstractHoverInformationControlManager.presentInformation(AbstractHoverInformationControlManager.java:902)
at org.eclipse.jface.text.TextViewerHoverManager.doPresentInformation(TextViewerHoverManager.java:243)
at org.eclipse.jface.text.TextViewerHoverManager$5.run(TextViewerHoverManager.java:233)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
... 24 more
and the message of the annotation is not shown.
What I want: I want, that if i hover iver an error where a quick fix is available, the quick fix is shown and if there is no one, just the annotation message is shown.

Related

Cannot retrieve object from IgniteCach, throws ClassNotFoundException

I am trying to add Ignite to an existing apache-tomcat application and I am running into an issue trying to retrieve data that I have previously inserted into an IgniteCache.
Below is a mockup of the code in question.
public static MyClass getInstance(){
Ignite ig = WSUtil.getIgnite();
IgniteCache<Integer,MyClass> myCache = ig.getOrCreateCache("MyClass");
MyClass instance = myCache.get( 0 );
if(instance == null) {
try{
instance = //IO opperations to create instance
myCache.put(0, instance);
}catch(Exception e) {
log.error("\tMessage: "+e.getMessage());
throw e;
}finally {
//close IO
}
}
return instance;
}
The first time this method is called an instance variable is successful created and stored but the second time it is called, the following errors occur when myCache.get( 0 ) is called :
javax.cache.CacheException: class org.apache.ignite.IgniteCheckedException: com.xxxx.services.MyClass
at com.xxxx.services.misc.impl.yyyy.getInstance(yyyy.java:84)
at com.xxxx.services.misc.impl.zzzz.getProductName(zzzz.java:324)
at com.xxxx.services.misc.impl.cccc.getProductName(cccc.java:92)
at com.xxxx.services.misc.impl.cccc.getProductInfo(cccc.java:752)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at com.xxxx.prime.aop.MethodCachingInterceptor.invoke(MethodCachingInterceptor.java:56)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy52.getProductInfo(Unknown Source)
at com.xxxx.ws.ProductInfoWS.invoke(ProductInfoWS.java:60)
at com.xxxx.ws.ProductInfoWS.invoke(ProductInfoWS.java:25)
at com.sun.xml.ws.api.server.InstanceResolver$1.invokeProvider(InstanceResolver.java:256)
at com.sun.xml.ws.server.InvokerTube$2.invokeProvider(InvokerTube.java:156)
at com.sun.xml.ws.server.provider.SyncProviderInvokerTube.processRequest(SyncProviderInvokerTube.java:78)
at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:595)
at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:554)
at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:539)
at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:436)
at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:243)
at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:444)
at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:244)
at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:135)
at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doGet(WSServletDelegate.java:129)
at com.sun.xml.ws.transport.http.servlet.WSServlet.doGet(WSServlet.java:82)
at java.lang.Thread.run(Thread.java:748)
Caused by: class org.apache.ignite.IgniteCheckedException: com.xxxx.services.MyClass
... 60 more
Caused by: class org.apache.ignite.binary.BinaryInvalidTypeException: com.xxxx.services.MyClass
... 1 more
Caused by: java.lang.ClassNotFoundException: com.xxxx.services.MyClass
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
... 29 more
I have tried to so something similar with a simple Person object running an Ignite server on my workstation without any problem.
public static void main (String[] args) throws IgniteException{
//preparing igniteconfig
IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setClientMode(true);
cfg.setPeerClassLoadingEnabled(true);
TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder();
ipFinder.setAddresses(Collections.singletonList("127.0.0.1:47500..47509"));
cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(ipFinder));
Ignite ignite = Ignition.start(cfg);
IgniteCache <Integer, Person> personCache = ignite.getOrCreateCache("personCache");
Person p = new Person("Billy","Jean");
personCache.put(0, p);
Person p2 = personCache.get(0);
System.out.println("p: " + p.toString());
System.out.println("p2: " + p2.toString());
System.out.println(">> task exectued, check output");
ignite.close();
}
It's quite possible that Ignite and your code are loaded from two different classloaders (as you have pointed out), such as, Apache Ignite may be loaded from the common libraries directory while the user code may be loaded from a specific web app directory. In this case, Apache Ignite may not see your libraries.
You can try setting IgniteConfiguration.classLoader property to e.g. getClass().getClassLoader() before starting Ignite node.

How to read data from smart card using jmrtd and scuba

I'm trying to read data from ePassporta using jmrtd and scuba.
But it doesn’t work. In Android, almost the same code works.
And when reading from a smart card it doesn’t work.
My method for reading:
public static void reader() throws Exception {
try {
CardTerminal terminal =TerminalFactory.getDefault().terminals().list().get(0);
CardService cs = CardService.getInstance(terminal);
PassportService service = new PassportService(cs);
service.open();
BACKeySpec bacKey = new BACKey("12312312312312", "31121990", "311230");
boolean paceSucceeded = false;
try {
CardAccessFile cardAccessFile = new CardAccessFile(service.getInputStream(PassportService.EF_CARD_ACCESS));
Collection<PACEInfo> paceInfos = cardAccessFile.getPACEInfos();
if (paceInfos != null && paceInfos.size() > 0) {
PACEInfo paceInfo = paceInfos.iterator().next();
service.doPACE(bacKey, paceInfo.getObjectIdentifier(), PACEInfo.toParameterSpec(paceInfo.getParameterId()));
paceSucceeded = true;
} else {
paceSucceeded = true;
}
} catch (Exception e) {
e.printStackTrace();
}
service.sendSelectApplet(paceSucceeded);
if (!paceSucceeded) {
try {
service.getInputStream(PassportService.EF_COM).read();
} catch (Exception e) {
service.doBAC(bacKey);
}
}
LDS lds = new LDS();
CardFileInputStream dg1In = service.getInputStream(PassportService.EF_DG1);
lds.add(PassportService.EF_DG1, dg1In, dg1In.getLength());
DG1File dg1File = lds.getDG1File();
System.out.println(dg1File.getMRZInfo().toString());
} catch (CardServiceException e) {
e.printStackTrace();
}
}
pom.xml
<dependency>
<groupId>org.jmrtd</groupId>
<artifactId>jmrtd</artifactId>
<version>0.5.2</version>
</dependency>
<dependency>
<groupId>net.sf.scuba</groupId>
<artifactId>scuba-sc-j2se</artifactId>
<version>0.0.13</version>
</dependency>
<dependency>
<groupId>net.sf.scuba</groupId>
<artifactId>scuba-smartcards</artifactId>
<version>0.0.13</version>
</dependency>
Stacktrace :
add more text just for stack overflow to accept the question.
added full stacktrace content.
added full stacktrace content.
added full stacktrace content.
added full stacktrace content.
D:\Java\jdk\bin\java -Didea.launcher.port=7539 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 14.0\bin" -Dfile.encoding=UTF-8 -classpath "D:\Java\jdk\jre\lib\charsets.jar;D:\Java\jdk\jre\lib\deploy.jar;D:\Java\jdk\jre\lib\javaws.jar;D:\Java\jdk\jre\lib\jce.jar;D:\Java\jdk\jre\lib\jfr.jar;D:\Java\jdk\jre\lib\jfxswt.jar;D:\Java\jdk\jre\lib\jsse.jar;D:\Java\jdk\jre\lib\management-agent.jar;D:\Java\jdk\jre\lib\plugin.jar;D:\Java\jdk\jre\lib\resources.jar;D:\Java\jdk\jre\lib\rt.jar;D:\Java\jdk\jre\lib\ext\access-bridge-32.jar;D:\Java\jdk\jre\lib\ext\cldrdata.jar;D:\Java\jdk\jre\lib\ext\dnsns.jar;D:\Java\jdk\jre\lib\ext\jaccess.jar;D:\Java\jdk\jre\lib\ext\jfxrt.jar;D:\Java\jdk\jre\lib\ext\localedata.jar;D:\Java\jdk\jre\lib\ext\nashorn.jar;D:\Java\jdk\jre\lib\ext\sunec.jar;D:\Java\jdk\jre\lib\ext\sunjce_provider.jar;D:\Java\jdk\jre\lib\ext\sunmscapi.jar;D:\Java\jdk\jre\lib\ext\sunpkcs11.jar;D:\Java\jdk\jre\lib\ext\zipfs.jar;C:\Users\maksat\IdeaProjects\smart_card\target\classes;C:\Users\maksat\.m2\repository\org\jmrtd\jmrtd\0.5.2\jmrtd-0.5.2.jar;C:\Users\maksat\.m2\repository\org\bouncycastle\bcprov-jdk15on\1.52\bcprov-jdk15on-1.52.jar;C:\Users\maksat\.m2\repository\net\sf\scuba\scuba-sc-j2se\0.0.11\scuba-sc-j2se-0.0.11.jar;C:\Users\maksat\.m2\repository\net\sf\scuba\scuba-smartcards\0.0.9\scuba-smartcards-0.0.9.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 14.0\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain paket.ReadFromSmartCard
net.sf.scuba.smartcards.CardServiceException: File not found, CAPDU = 00A4020C02011C, RAPDU = 6A82 (SW = 0x6A82: FILE NOT FOUND)
at org.jmrtd.PassportApduService.checkStatusWordAfterFileOperation(Unknown Source)
at org.jmrtd.PassportApduService.sendSelectFile(Unknown Source)
at org.jmrtd.PassportService.sendSelectFile(Unknown Source)
at org.jmrtd.MRTDFileSystem.getFileInfo(Unknown Source)
at org.jmrtd.MRTDFileSystem.getSelectedPath(Unknown Source)
at net.sf.scuba.smartcards.CardFileInputStream.<init>(CardFileInputStream.java:56)
at org.jmrtd.PassportService.getInputStream(Unknown Source)
at paket.ReadFromSmartCard.sdvsdv(ReadFromSmartCard.java:121)
at paket.ReadFromSmartCard.readData(ReadFromSmartCard.java:89)
at paket.ReadFromSmartCard.main(ReadFromSmartCard.java:23)
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.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
ноя 19, 2019 10:45:51 AM org.jmrtd.PassportService doBAC
WARNING: BAC failed for BAC key "21009199301195, 100993, 120229"
net.sf.scuba.smartcards.CardServiceException: Mutual authentication failed: expected length: 40 + 2, actual length: 2 (SW = 0x6985: CONDITIONS NOT SATISFIED)
at org.jmrtd.PassportApduService.sendMutualAuth(Unknown Source)
at org.jmrtd.PassportService.doBAC(Unknown Source)
at org.jmrtd.PassportService.doBAC(Unknown Source)
at paket.ReadFromSmartCard.sdvsdv(ReadFromSmartCard.java:140)
at paket.ReadFromSmartCard.readData(ReadFromSmartCard.java:89)
at paket.ReadFromSmartCard.main(ReadFromSmartCard.java:23)
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.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Process finished with exit code 0

Can i declare and initialize ImageView outside for and swtich statement and set its property withing them?

This code is working (ImageView is decared globally but initializing and setting its property in the for and switch statement)
private static ImageView imgP;
public static Pane board = new Pane();
public void start(Stage primaryStage)throws Exception {
Rectangle r1,r;
for(int i = 0;i<64;i+=2) {
r = new Rectangle((i%8 + (i/8)%2)*tileSize,(i/8)*tileSize, tileSize,tileSize);
r.setFill(Color.rgb(255,200,100));
r1 = new Rectangle(((i+1)%8-(((i+1)/8)%2))*tileSize,(((i+1))/8)*tileSize,tileSize,tileSize);
r1.setFill(Color.rgb(150,50,30));
board.getChildren().addAll(r,r1);
}
for(int i = 0;i<64;i++) {
switch(Test.board[i/8][i%8]) {
case "P":
imgP = new ImageView(new Image("images/11.png"));
imgP.setFitWidth(tileSize);
imgP.setFitHeight(tileSize);
imgP.setX((i%8 )*tileSize);
imgP.setY((i/8)*tileSize);
board.getChildren().add(imgP);
break;
}
}
Scene scene = new Scene(board);
primaryStage.setScene(scene);
primaryStage.show();
}
}
This code does not (ImageView is decared globally and initialized outside for and switch statement while setting its property aftewards)
private static ImageView imgP;
public static Pane board = new Pane();
public void start(Stage primaryStage)throws Exception {
Rectangle r1,r;
ImageView imgP = new ImageView(new Image("images/11.png"));
for(int i = 0;i<64;i+=2) {
r = new Rectangle((i%8 + (i/8)%2)*tileSize,(i/8)*tileSize, tileSize,tileSize);
r.setFill(Color.rgb(255,200,100));
r1 = new Rectangle(((i+1)%8-(((i+1)/8)%2))*tileSize,(((i+1))/8)*tileSize,tileSize,tileSize);
r1.setFill(Color.rgb(150,50,30));
board.getChildren().addAll(r,r1);
}
for(int i = 0;i<64;i++) {
switch(Test.board[i/8][i%8]) {
case "P":
imgP.setFitWidth(tileSize);
imgP.setFitHeight(tileSize);
imgP.setX((i%8 )*tileSize);
imgP.setY((i/8)*tileSize);
board.getChildren().add(imgP);
break;
}
}
Scene scene = new Scene(board);
primaryStage.setScene(scene);
primaryStage.show();
}
}
The error is generated is as follows:
Exception in Application start method
Exception in thread "main" 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 sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
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$154(LauncherImpl.java:182)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: Children: duplicate children added: parent = Pane#5a3b6136
at javafx.scene.Parent$2.onProposedChange(Parent.java:454)
at com.sun.javafx.collections.VetoableListDecorator.add(VetoableListDecorator.java:206)
at FrontEnd.start(FrontEnd.java:47)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(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$147(WinApplication.java:177)
Please explain with reasoning.
In JavaFX a Node cannot be added to the same parent more than once at the same time. That's why you're getting this exception:
Caused by: java.lang.IllegalArgumentException: Children: duplicate children added: parent = Pane#5a3b6136
at javafx.scene.Parent$2.onProposedChange(Parent.java:454)
at com.sun.javafx.collections.VetoableListDecorator.add(VetoableListDecorator.java:206)
at FrontEnd.start(FrontEnd.java:47)
// Omitted rest of stack trace for brevity...
In your code you call board.getChildren().add(imgP) each iteration of the for loop. The problem in the second example is imgP is the same instance each time. In the first example you create a new instance each iteration.
If your goal is to avoid creating multiple Images of the same thing then what you should be doing is sharing the same Image instance between multiple ImageViews.

JavaFX Exception in Application start method (java.lang.IllegalStateException: Location is not set.)

I tried moving my fxml file around but I can't seem to get the right path to my file. Also does my controller have to be in the same package as my fmxl file. I read online I should put my fxml file into the resources folder and that's what I did but it's still not working. My controller is in the UI folder should I move that to the resource folder?
public class Main extends Application{
public Main() {
}
private static ArgumentParser argumentParser;
private static Stage primaryStage;
private static ArgumentResponder argumentResponder;
private static UncaughtExceptionLogger uncaughtExceptionLogger;
private static Settings settings;
/**
* The main method, for starting the application.
*
* <p>See {#link Argument} for the supported arguments.</p>
*
* #param args arguments given when starting KouChat.
*/
public static void main(String[] args){
argumentParser = new ArgumentParser(args);
argumentResponder = new ArgumentResponder(argumentParser);
if (!argumentResponder.respond()) {
return;
}
new LogInitializer(argumentParser.hasArgument(Argument.DEBUG));
// Initialize as early as possible to catch all exceptions
uncaughtExceptionLogger = new UncaughtExceptionLogger();
settings = loadSettings(argumentParser);
launch(args);
}
private static Settings loadSettings(final ArgumentParser argumentParser) {
final Settings settings = new Settings();
final ArgumentSettingsLoader argumentSettingsLoader = new ArgumentSettingsLoader();
argumentSettingsLoader.loadSettings(argumentParser, settings);
final PropertyFileSettingsLoader propertyFileSettingsLoader = new PropertyFileSettingsLoader();
propertyFileSettingsLoader.loadSettings(settings);
return settings;
}
#Override
public void start(Stage primaryStageObj) throws Exception{
primaryStage = primaryStageObj;
System.out.println(getClass().getResource("Chat.fxml"));
FXMLLoader loader = new FXMLLoader(getClass().getResource("Chat.fxml"));
ChatController pls = new ChatController(argumentParser, settings, uncaughtExceptionLogger);
loader.setController(pls);
pls.setStage(primaryStage);
Parent root = loader.load();
primaryStage.setTitle("Flake");
primaryStage.setScene(new Scene(root, 959,583 ));
primaryStage.setResizable(false);
primaryStage.show();
primaryStage.setResizable(false);
primaryStage.setOnCloseRequest(e -> Platform.exit());
}
}
This is my project path to help see where I am going wrong
The error message I am receiving when running my code.
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$154(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalStateException: Location is not set.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2434)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
at net.usikkert.kouchat.Main.start(Main.java:71)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(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$147(WinApplication.java:177)
... 1 more
Exception running application net.usikkert.kouchat.Main

openIMAJ face detection - uncaught IOException

I have this method(simplified) for detecting faces(count) on images(URLs):
private int processImage(String urlString) {
InputStream is = null;
URLConnection resource;
int facesCount = 0;
try {
resource = new URL(urlString).openConnection();
resource.setConnectTimeout(200);
resource.setReadTimeout(1000);
resource.setRequestProperty("User-Agent", "Mozilla/5.0");
String type = resource.getHeaderField("Content-Type");
if (!type.startsWith("image/")) {
throw new IOException("Not an image (Content-Type:" + type + ")");
}
is = resource.getInputStream();
MBFImage mbfimage = ImageUtilities.readMBF(is);
facesCount = faceDetector.detectFaces(Transforms.calculateIntensity(mbfimage)).size();
is.close();
} catch (IOException e) {
System.out.println("oops");
}
return facesCount;
}
It works well, but if the image is somewhat corrupted (for example this test image), i get this error:
Error: Cannot decode the image for the type : Occurs in:
com.sun.media.jai.opimage.CodecRIFUtil java.io.IOException: Source
stream does not support seeking backwards. at
com.sun.media.jai.codecimpl.CodecUtils.toIOException(CodecUtils.java:76)
at
com.sun.media.jai.codecimpl.FPXImageDecoder.decodeAsRenderedImage(FPXImageDecoder.java:40)
at
com.sun.media.jai.opimage.CodecRIFUtil.create(CodecRIFUtil.java:88)
at com.sun.media.jai.opimage.FPXRIF.create(FPXRIF.java:46) at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606) at
javax.media.jai.FactoryCache.invoke(FactoryCache.java:122) at
javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1674)
at
javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:473)
at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:332)
at com.sun.media.jai.opimage.StreamRIF.create(StreamRIF.java:102) at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606) at
javax.media.jai.FactoryCache.invoke(FactoryCache.java:122) at
javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1674)
at
javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:473)
at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:332)
at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:819) at
javax.media.jai.RenderedOp.createRendering(RenderedOp.java:867) at
javax.media.jai.RenderedOp.getColorModel(RenderedOp.java:2242) at
javax.media.jai.PlanarImage.getAsBufferedImage(PlanarImage.java:2498)
at
javax.media.jai.PlanarImage.getAsBufferedImage(PlanarImage.java:2546)
at org.openimaj.image.ExtendedImageIO.read(ExtendedImageIO.java:162)
at org.openimaj.image.ImageUtilities.readMBF(ImageUtilities.java:273)
at image.ImageThread.processImage(ImageThread.java:233) at
image.ImageThread.main(ImageThread.java:255) Caused by:
java.lang.IllegalArgumentException: Source stream does not support
seeking backwards. at
com.sun.media.jai.codec.SegmentedSeekableStream.(SegmentedSeekableStream.java:200)
at
com.sun.media.jai.codec.SegmentedSeekableStream.(SegmentedSeekableStream.java:262)
at
com.sun.media.jai.codecimpl.fpx.StructuredStorage.getFat(StructuredStorage.java:238)
at
com.sun.media.jai.codecimpl.fpx.StructuredStorage.(StructuredStorage.java:131)
at com.sun.media.jai.codecimpl.fpx.FPXImage.(FPXImage.java:110)
at
com.sun.media.jai.codecimpl.FPXImageDecoder.decodeAsRenderedImage(FPXImageDecoder.java:38)
... 28 more
and the program hangs. I want to catch that exception, log it and go on.
Could you please help me?
Ok, I found the solution. I was using old version of openIMAJ (1.1.3). The latest version is 1.3.1 which works well. I didn't notice, because I overlooked the version numbers.

Categories

Resources