Exception in use of OpenCV - java

Following is code which i am running :
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
public class Main_Extraction
{
public static void main( String[] args )
{
System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
Mat mat = Mat.eye( 3, 3, CvType.CV_8UC1 );
System.out.println( "mat = " + mat.dump() );
}
}
this code is having no compile time error.
but, it's giving me run-time exception which is :
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: <any>
at Main_Extraction.main(Main_Extraction.java:9) Java Result: 1
please, suggest the solution to remove this exception.

I had the same problem. Here is the solution, add this paths in your environment variable CLASSPATH. this will work.
C:\javacv\javacv.jar;
C:\javacv\javacpp.jar;
C:\javacv\javacv-windows-x86.jar;
C:\javacv\jna.jar;C:\javacv;
c:\opencv2.4\build\x86\vc10\bin;
set this according to your javacv installed folder.

You have attempted run a program that has compilation error in it. Fix the compilation errors BEFORE you try to run your program!!
this code is having no compile time error.
That is not true. The actual "compiled" bytecode file you are attempting to run is throwing an exception that says clearly that there was a compilation error of some kind.
Perhaps you are trying to compile a stale version ...
Perhaps you are compiling against a corrupted copy of the OpenCV JAR.
Perhaps you are using a buggy compiler ... and it crashed, giving you a bogus ".class" file.

Please check if the PATH variable is set correctly and opencv libraries are included, there is nothing wrong in the code.
Please follow this tutorial here for step by step installation of opencv in eclipse
http://nenadbulatovic.blogspot.de/2013/07/configuring-opencv-245-eclipse-cdt-juno.html

Related

Could not find or load main class in a simple java project

I have created a simple java project "DesignPatterns".
I created a file FacadePattern.java with the path being ~/DesignPatterns/Structural/FacadePattern/FacadePattern.java
My FacadePattern.java class,
public class FacadePattern {
public static void main(String args[]) {
// Some code
}
}
But my editor (VSCode) gives me an error at the start of the file:
The declared package "" does not match the expected package "Structural.DecoratorPattern"
So upon clicking on quick fix, it added package Structural.FacadePattern; in the first line.
So the final code became
package Structural.FacadePattern;
public class FacadePattern {
public static void main(String args[]) {
// Some code
}
}
But when I compile the above file using the command
javac FacadePattern.java && java FacadePattern
It is giving me the following error:
Error: Could not find or load main class FacadePattern
Caused by: java.lang.NoClassDefFoundError: Structural/FacadePattern/FacadePattern (wrong name: FacadePattern)
After searching a lot in the internet, I ran the following command:
javac -sourcefile ~/DesignPatterns FacadePattern.java && java FacadePattern
But no use, I am getting the same error.
Can anyone explain why my editor gave an error but code ran successfully before? and why wont it compile after adding "package Structural.FacadePattern;" line? and what is -sourcefile parameter in javac command? and how to run the code with successfully without errors in editor as well as the terminal?
Stick to naming rules. Package names should be lowercase only. In your case, it should be package structural.facadepattern;
Run the 'correct' class. Because your class is not inside 'the base folder' aka the 'default package', you have to prefix the class with its package name: java Structural.FacadePattern.FacadePattern or rather java structural.facadepattern.FacadePattern if you use the proper case for packages.

Null Pointer Exception reading h2o Mojo Zip

I am trying to write a java wrapper to use my h2o mojo model. When I load my model zip files in, I receive a null pointer exception. Below is a sample of my code:
public static void main(String[] args) throws Exception {
EasyPredictModelWrapper predict_model = new EasyPredictModelWrapper(
MojoModel.load("prediction_football_model.zip"));
EasyPredictModelWrapper class_model = new EasyPredictModelWrapper(
MojoModel.load("classification_football_model.zip"));
}
and error Message:
Exception in thread "main" java.lang.NullPointerException: entry
at java.util.zip.ZipFile.getInputStream(ZipFile.java:346)
at hex.genmodel.ZipfileMojoReaderBackend.getTextFile(ZipfileMojoReaderBackend.java:18)
at hex.genmodel.ModelMojoReader.parseModelInfo(ModelMojoReader.java:154)
at hex.genmodel.ModelMojoReader.readFrom(ModelMojoReader.java:27)
at hex.genmodel.MojoModel.load(MojoModel.java:35)
at GamePrediction.main(GamePrediction.java:52)
I have been working on this code in eclipse and I have placed both of the zip files in the main project folder. I created the models in R using the h2o.download_mojo() function. I looked into the error message and found that my ZipEntry for the given path's were Null, but I could not find a solution to that.
Any help or insight would be helpful. I couldn't find any other issues like this so if this is a duplicate, please point me to the right direction!
I got the same error and resolved it.
In my case, the mojo runtime file had a problem. I was using 1.8.1.1, and a bug discovered around the time of the version. I simply replaced the file with the latest one. Then everything worked like a charm.
Here is the link for the file. Please notice that this may not be the latest one for you. https://s3.amazonaws.com/artifacts.h2o.ai/releases/ai/h2o/mojo2-runtime/2.5.9/any/mojo2-runtime-2.5.9-all.jar

compilation java javax.el.ExpressionFactory

i tried to compile a code, this class compiled and i broke someth
I search impossible to find this method and which jar miss
import javax.el.ExpressionFactory
org.apache.commons.jexl2.Expression e = ExpressionFactory.newInstance().createExpression;
i tried to add commons-jexl_2.1.1.jar and i hava this error
Multiple markers at this line
- The method createExpression(String) is undefined for the type
ExpressionFactory
i tried grepcode but it seem not recognized createExpression
Do you have any ideas?
Thanks

java.lang.NoSuchMethodError - Ljava/lang/String;)Ljava/lang/String;

My code is giving an error below;
Exception in thread "main" java.lang.NoSuchMethodError:
com/myApp/Client.cypherCBC(Ljava/lang/String;)Ljava/lang/String;
But it's working fine in an another local environment. My code so far is below;
try {
System.out.println("Encrypted CBC passwd : "
+ Client.cypherCBC("CypherThePassword"));
} catch (Exception e) {
e.printStackTrace();
}
This is due to a run-time JAR or class mismatch. the "Client" class which was there at the time you compile your application has a static method "cypherCBC" which gets String parameter, but at run-time class loader has loaded the "Client" class which doesn't have that kind of method (same name with same signature).
if you can debug the application at runtime, put a break-point at the line which exception was thrown, then try to evaluate following expression,
Client.class.getResource("Client.class")
, then you can find where the class has been leaded from, then you can decompile and try to troubleshoot the issue.
I got the same error while running a web application in Weblogic.
The reason for this error is there are two versions of classes are in the environment.To fix this you have to figure out which .class is using at the run time.
I used following to identify which class is loaded at run time.
-verbose:class
There is a duplicate class on your classpath.
So, That is why JVM is getting confused that which one needs to pick because both classes have a same method with a different signature that you are trying to call.

Drools: NullPointerException when addPackageFromDrl(source) is called

I'm trying to execute a simple HelloWorld rule within an OSGi application. During parsing and compiling however, the following exception occurs:
java.lang.NullPointerException
at org.drools.rule.builder.RuleBuilder.build(RuleBuilder.java:47)
at org.drools.compiler.PackageBuilder.addRule(PackageBuilder.java:446)
at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:304)
at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:167)
The DRL file is found by the application, since introducing syntax errors results in a failed compilation warning. I guess I'm overlooking something trivial, but haven't found it yet...
I'm using Drools 4.0.7, since this one was available on the Springsource Enterprise Bundle Repository. Here are my application code and drl:
//read in the source
Reader source = new InputStreamReader( getClass().getResourceAsStream( "hello.drl" ) );
PackageBuilder builder = new PackageBuilder();
//this wil parse and compile in one step
builder.addPackageFromDrl( source );
// Check the builder for errors
if ( builder.hasErrors() ) {
System.out.println( builder.getErrors().toString() );
throw new RuntimeException( "Unable to compile \"hello.drl\".");
}
//get the compiled package (which is serializable)
org.drools.rule.Package pkg = builder.getPackage();
//add the package to a rulebase (deploy the rule package).
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage( pkg );
StatefulSession session = ruleBase.newStatefulSession();
session.fireAllRules();
#created on: May 1, 2011
package test
rule "A stand alone rule"
when
eval(true)
then
System.out.println("hello world");
end
As always, help is highly appreciated.
KR,
Niels
EDIT: During debugging I noticed that the internal builder object within the PackageBuilder was null, as were the package and packagedescription. I got around the original problem by adding this description manually:
PackageBuilder builder = new PackageBuilder();
PackageDescr packageDescr = new PackageDescr("be.ugent.intec.doctr.processor.job.fever");
builder.addPackage(packageDescr);
//this will parse and compile in one step
builder.addPackageFromDrl( source );
My rule was edited to the following form:
package be.ugent.intec.doctr.processor.job.fever
rule "hello"
when
eval( true )
then
System.out.println("hello there");
end
This however results in a compile failure:
BR.recoverFromMismatchedToken
[1,0]: unknown:1:0 mismatched token: [#0,0:6='println',<7>,1:0];
java.lang.RuntimeException: Unable to compile "hello.drl".
at be.ugent.intec.doctr.processor.job.fever.FeverJob.execute(FeverJob.java:45)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525)
When removing the package line from the rule, then my example goes all the way through, without printing anything however. Am I again overlooking anything? I guess this is related to an issue within the drl itself, considering everything stands or falls with the declaration of the package. Just to be clear, the drl is loaded in a class contained in the package be.ugent.intec.doctr.processor.job.fever.
Thx!
A NullPointerException shouldn't happen during compilation: either you get a clear compilation error during parsing (which includes line number) or it works. Drools 4.0.7 is old. This is probably already fixed in a newer version of drools. If it isn't, raise a JIRA issue.
Try a more up-to-date version of drools, preferably even a 5.2 version (5.2.0.CR1 will be out later today or tomorrow), which uses the new, better parser.

Categories