how i can get real path of file.xml from web-inf in ZUL, i try this:
org.zkoss.zrss.RssFeed feed;
org.zkoss.zrss.RssBinder binder = new org.zkoss.zrss.RssBinder();
try {
feed = binder.lookUpFeed(new File("/WEB-INF/lesscoutsBeRss.xml").toURI().toURL().toString());
} catch (Exception e) {
e.getStackTrace();
}
but i have problem ,I think the problem because of the bad good recovery path
Failed to load /MainPage/rss_lesscouts.zul
Cause: Null Pointer in Method Invocation
java.lang.NullPointerException: Null Pointer in Method Invocation
at bsh.Name.invokeMethod(Unknown Source)
at bsh.BSHMethodInvocation.eval(Unknown Source)
at bsh.BSHPrimarySuffix.doSuffix(Unknown Source)
at bsh.BSHPrimaryExpression.eval(Unknown Source)
at bsh.BSHPrimaryExpression.eval(Unknown Source)
at bsh.BSHVariableDeclarator.eval(Unknown Source)
at bsh.BSHTypedVariableDeclaration.eval(Unknown Source)
at bsh.Interpreter.eval(Unknown Source)
at bsh.Interpreter.eval(Unknown Source)
...
You may try to use this, in order to retrieve the full path of WEB-INF folder in a ZK project:
Sessions.getCurrent().getWebApp().getRealPath("")+"/WEB-INF/"
Hope this helps you.
Related
I am trying to inject a .jar file in a running VM.
I've added tools.jar in the build path in eclipse, but when I try to run the injector, this error pops up. How should I add tools.jar to the project?
Full error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/attach/VirtualMachine
at src.testinjector.MainClass.main(MainClass.java:13)
Caused by: java.lang.ClassNotFoundException: com.sun.tools.attach.VirtualMachine
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
you may try:
Give the path to tools.jar instead of being dependent on JAVA_HOME.
Note: JAVA_HOME/path to jdk/bin/ should not have any space.
By default, the "tools.jar" classes are not loaded, your options are to either use a jdk that does load it, include tools.jar in your jar, or forcefully load it with the method below, (note: this might not work on certain jdk/jvm's)
private static void prepareAttach() throws NoSuchMethodException, MalformedURLException, InvocationTargetException, IllegalAccessException {
String binPath = System.getProperty("sun.boot.library.path");
// remove jre/bin, replace with lib
String libPath = binPath.substring(0, binPath.length() - 7) + "lib";
URLClassLoader loader = (URLClassLoader) [This Class].class.getClassLoader();
Method addURLMethod = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
addURLMethod.setAccessible(true);
File toolsJar = new File(libPath + "/tools.jar");
if (!toolsJar.exists()) throw new RuntimeException(toolsJar.getAbsolutePath() + " does not exist");
addURLMethod.invoke(loader, new File(libPath + "/tools.jar").toURI().toURL());
}
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 5 years ago.
I currently am trying to make a risk-like game and as I try to display a map (vectorial image) I have a NullPointerException that I do not understand at all how it can be solved. =/
Here's the code :
public class Test1 extends Stage {
private BorderPane root = new BorderPane();
private WebView browser = new WebView();
public Test1(){
this.setTitle("Test1");
this.setScene(new Scene(content()));
}
Parent content(){
WebEngine webEngine = browser.getEngine();
webEngine.load(this.getClass().getResource("../../resources/worldMap.html").toExternalForm());
root.setCenter(browser);
return root;
}
}
and the error :
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(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(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$155(LauncherImpl.java:182)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at hmi.Test1.content(Test1.java:23)
at hmi.Test1.<init>(Test1.java:18)
at Main.start(Main.java:13)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.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(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)
... 1 more
Exception running application Main
So it seems to be caused by the link "../../resources/worldMap.html" but it really leads to the file. I also tried with a svg file or with an url (this one : https://upload.wikimedia.org/wikipedia/commons/8/80/World_map_-_low_resolution.svg )
and I still have the exact same error.
It's been a day I'm stuck on that despite my researchs on internet, so I hope you will be able to help me.
Thanks !
I can't say for certain from the pasted code, but I think I can help you debug it. You've identified webEngine.load(this.getClass().getResource("../../resources/worldMap.html").toExternalForm()); as the errant line in one of your comments.
The NPE means one of the things you are using in that line is null in an unexpected way. Are you using an IDE with a debugger? Set a break-point on that line and evaluate each subcomponent.
If not, you really should try one. I use intellij and find it makes me far more effective and efficient. In the interim, the hackiest simplest way to figure this out is with a bunch of print statements
System.out.println("webEngine" + webEngine);
System.out.println("class" + this.getClass());
System.out.println("resource" + this.getClass().getResource("../../resources/worldMap.html"));
System.out.println("loaded" + webEngine.load(this.getClass().getResource("../../resources/worldMap.html"));
One of these things will be null and the next line will throw an NPE. That way, you'll know where in the stack you have a problem. Please post back when you find it. I would guess that either using the this.getClass.getResource is wrong or the place you think the relative path starts from in your path string is wrong (usually it is relative to where your .class paths are written).
Have you tried using an absolute path instead to load your resource? It's possible where you think your code is executing from and where it's actually executing from are different.
Ok, I finally found out the answer.
My question is actually a duplicate of Class.getResource() returns null
And the answer was that the image had to be in the same directory as the package where the class on which I apply the "getclass" is, while it was in the root of the project.
Thank you for your help though !
I am extracting text from image pdf using Tes4j.
There are two steps involved here:
1)convert pdf to image:
PdfUtilities.convertPdf2Png(inputfilepath);
This works without any issues.
2)extract text from image:
try {
if(imgName.endsWith(".png")){
ITesseract instance = new Tesseract();
instance.setDatapath("tessdataPath");
extractedData= instance.doOCR(Image);
}
catch(Exception e2){
System.out.println("exception:"+e2.getMessage());
}
}
}
While doing this I get below exception for specific image file.
Exception in thread "main" java.lang.Error: Invalid memory access
at com.sun.jna.Native.invokePointer(Native Method)
at com.sun.jna.Function.invokePointer(Function.java:470)
at com.sun.jna.Function.invoke(Function.java:404)
at com.sun.jna.Function.invoke(Function.java:315)
at com.sun.jna.Library$Handler.invoke(Library.java:212)
at com.sun.proxy.$Proxy1.TessBaseAPIGetUTF8Text(Unknown Source)
at net.sourceforge.tess4j.Tesseract.getOCRText(Unknown Source)
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
at com.tcs.textExtraction.ImgToText.imagetoText(ImgToText.java:109)
at com.tcs.textExtraction.ImgToText.main(ImgToText.java:31)
split_pt >0 && split_pt < word->chopped_word->NumBlobs():Error:Assert failed:in file ..\..\ccmain\tfacepp.cpp, line 186
I have included following jars:
jna.jar,log4j-1.2.17.jar,pdfbox-1.8.13.jar,tess4j.jar,commons-logging-1.1.3.jar,fontbox-1.8.13.jar,ghost4j-0.5.1.jar,itext-2.1.7.jar,jai_imageio.jar
my tessdata has following files:
pdf.ttf,pdf.ttx,eng.traineddata,osd.traineddata
I get following exception with new cobertura (2.0.2..). I guess it is some how related to new object creation immediately in a new block.
WARN instrumentClass, Unable to instrument file c:\apps\ijprojects\TrickyInstrument\out\production\TrickyInstrument\InstrumentationFailsOnFirstNewClassInTryBlock.class
java.lang.RuntimeException: java.lang.ClassNotFoundException: DataAccess
at org.objectweb.asm.ClassWriter.getCommonSuperClass(Unknown Source)
at org.objectweb.asm.ClassWriter.a(Unknown Source)
at org.objectweb.asm.Frame.a(Unknown Source)
at org.objectweb.asm.Frame.a(Unknown Source)
at org.objectweb.asm.MethodWriter.visitMaxs(Unknown Source)
at org.objectweb.asm.MethodVisitor.visitMaxs(Unknown Source)
at org.objectweb.asm.util.CheckMethodAdapter.visitMaxs(Unknown Source)
at org.objectweb.asm.MethodVisitor.visitMaxs(Unknown Source)
at org.objectweb.asm.commons.LocalVariablesSorter.visitMaxs(Unknown Source)
at org.objectweb.asm.tree.MethodNode.accept(Unknown Source)
at org.objectweb.asm.util.CheckMethodAdapter$1.visitEnd(Unknown Source)
at org.objectweb.asm.MethodVisitor.visitEnd(Unknown Source)
at org.objectweb.asm.util.CheckMethodAdapter.visitEnd(Unknown Source)
at org.objectweb.asm.ClassReader.b(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.instrumentClass(CoberturaInstrumenter.java:204)
at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.instrumentClass(CoberturaInstrumenter.java:121)
at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.addInstrumentationToSingleClass(CoberturaInstrumenter.java:233)
at net.sourceforge.cobertura.instrument.Main.addInstrumentationToSingleClass(Main.java:274)
at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:283)
at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:292)
at net.sourceforge.cobertura.instrument.Main.parseArguments(Main.java:373)
at net.sourceforge.cobertura.instrument.Main.main(Main.java:395)
8 Jul, 2013 2:05:07 PM net.sourceforge.cobertura.coveragedata.CoverageDataFileHandler saveCoverageData
INFO: Cobertura: Saved information on 2 classes.
The following is the code related to above exception.
public class InstrumentationFailsOnFirstNewClassInTryBlock {
public void saveToDatabase() {
//
try {
// boolean b=false;
// if ( b) {
// System.out.println("no action");
// }
DataAccess da = new DataAccess();
System.out.println("nothing");
} catch (Exception e) {
}
}
}
class DataAccess {
public DataAccess() {
//To change body of created methods use File | Settings | File Templates.
}
}
If I un-comment the code block some dummy statements , then instrumentation works fine. Has any one seen this? Any potential fixes?
Edit: Error occurs with java6 and java7.
Original problem was due to a Cobertura defect. It is not fixed. Cobertura now supports an additional argument for auxillary classpath.. This will be used to resolve any classes required for instrumentation.
cobertura-ant task documentation
Adding auxClasspath
auxClasspath argument is designed to remove the ClassNotFoundException
during instrumentation. See
https://github.com/cobertura/cobertura/wiki/FAQ#classnotfoundexception-during-instrumentation
for more information on this argument
I had a similar issue, and it may be a bug, see: https://github.com/cobertura/cobertura/issues/49
Your test case may be useful to debug the issue...
From https://github.com/cobertura/cobertura/wiki/FAQ#classnotfoundexception-during-instrumentation:
"This is because during instrumentation in cobertura 2.0, we use ASM to rebuild the .class files. We rebuild the stackmap which is a requirement to be compatible with java 7 and anything after. This does not mean that we recompile the code, however ASM requires that we provide the binaries of the other classes just in case it needs to look up any super methods. To fix this we use an argument called auxClasspath."
Adding the following code to your ant file (build.xml) should resolve the issue.
<path id="cobertura.auxpath">
<pathelement location="${bin}"/>
</path>
<target name="instrument_coverage" depends="init_coverage"
description="Instruments source code for coverage measurement">
<cobertura-instrument datafile="${coverage.datafile}">
<fileset refid="coverage-files"/>
<auxClasspath>
<path refid="cobertura.auxpath" />
</auxClasspath>
</cobertura-instrument>
</target>
This worked for me.
I tried to turn off importing documents in WSDL4J (1.6.2) in the way suggested
by the API documentation:
wsdlReader.setFeature("javax.wsdl.importDocuments", false);
In fact, it stops importing XML schema files declared with wsdl:import tag, but does stop importing files declared with xs:import tags.
The following code snippet [see at the end of the letter] for the example file
http://www.ibspan.waw.pl/~gawinec/example.wsdl
returns the following exception:
javax.wsdl.WSDLException: WSDLException (at /definitions/types/xs:schema):
faultCode=OTHER_ERROR: An error occurred trying to resolve schema referenced
at 'EchoExceptions.xsd', relative to
'http://www.ibspan.waw.pl/~gawinec/example.wsdl'.:
java.io.FileNotFoundException: This file was not found:
http://www.ibspan.waw.pl/~gawinec/EchoExceptions.xsd
at com.ibm.wsdl.xml.WSDLReaderImpl.parseSchema(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.parseSchema(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.parseTypes(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.parseDefinitions(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
at IsolatedExample.main(IsolatedExample.java:15)
Caused by: java.io.FileNotFoundException: This file was not found:
http://www.ibspan.waw.pl/~gawinec/EchoExceptions.xsd
at com.ibm.wsdl.util.StringUtils.getContentAsInputStream(Unknown Source)
... 10 more
Can you suggest me any solution to this problem? I just don't want to import
external XML schemata.
Regards,
Maciej
import javax.wsdl.WSDLException;
import javax.wsdl.factory.WSDLFactory;
import javax.wsdl.xml.WSDLReader;
public class IsolatedExample {
public static void main(String[] args) {
WSDLFactory wsdlFactory;
try {
wsdlFactory = WSDLFactory.newInstance();
WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
wsdlReader.setFeature("javax.wsdl.verbose", false);
wsdlReader.setFeature("javax.wsdl.importDocuments", false);
wsdlReader.readWSDL("http://www.ibspan.waw.pl/~gawinec/example.wsdl");
} catch (WSDLException e) {
e.printStackTrace();
}
}
}
A quick look at WSDL4J (it's been a while since I've worked directly with this project) suggests that there is no option specifically to prevent the reading of imported schemas. You may have stumbled upon on a bug in WSDL4J's mechanism of deserializing schemas. That said, if you're not interested in the contents of any schemas, including those inlined in the WSDL document, you can register your own extension registry (simply modify the PopulatedExtensionRegistry class to leave out the SchemaDeserializer).
Specifically, leave out the following lines:
mapExtensionTypes(Types.class, SchemaConstants.Q_ELEM_XSD_1999,
SchemaImpl.class);
registerDeserializer(Types.class, SchemaConstants.Q_ELEM_XSD_1999,
new SchemaDeserializer());
registerSerializer(Types.class, SchemaConstants.Q_ELEM_XSD_1999,
new SchemaSerializer());
mapExtensionTypes(Types.class, SchemaConstants.Q_ELEM_XSD_2000,
SchemaImpl.class);
registerDeserializer(Types.class, SchemaConstants.Q_ELEM_XSD_2000,
new SchemaDeserializer());
registerSerializer(Types.class, SchemaConstants.Q_ELEM_XSD_2000,
new SchemaSerializer());
mapExtensionTypes(Types.class, SchemaConstants.Q_ELEM_XSD_2001,
SchemaImpl.class);
registerDeserializer(Types.class, SchemaConstants.Q_ELEM_XSD_2001,
new SchemaDeserializer());
registerSerializer(Types.class, SchemaConstants.Q_ELEM_XSD_2001,
new SchemaSerializer());
I haven't used Java for webservices, but have you tried setting an absolute path to the schemas you import? Perhaps it's trying to load a local file.
You could also try sniffing the wire to see if you're making a request, perhaps it's malformed.
$0.02