Why can't Eclipse detect javacv functions beginning with cv - java

I'm learning JavaCV, and I found a really nice example online here in C++
http://aishack.in/tutorials/an-introduction-to-contours/
However, Eclips can't detect any of the functions that start with cv. like cvCreateImage(), even if the method is static. I'm at a loss for what to do here. Other Java tutorials for javacv also use these methods.
Thanks a lot in advance!

I found out why it didn't work - you have to add some static references at the top. This is what I added if anyone else is stuck
import com.googlecode.javacpp.Loader;
import com.googlecode.javacv.*;
import com.googlecode.javacv.cpp.*;
import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;
import static com.googlecode.javacv.cpp.opencv_calib3d.*;
import static com.googlecode.javacv.cpp.opencv_objdetect.*;
import static com.googlecode.javacv.cpp.opencv_highgui.*;

Related

Why Are These Imports Errored?

As part of my uni project, I have had to clone a group member's code and work on it myself. But on the imports included below, they are underlined and I can't seem to know why or how to address this. Netbeans says that these are 'Unused imports'. I've already tried to Google this but with no luck.
What does this mean and how do I fix it? Please bear with me as I am completely new to programming and it's concepts. Thank you.
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import static org.apache.http.HttpHeaders.USER_AGENT;
As the name implies, "Unused import" is a message from the IDE (not directly related to Java) and means that you're not using that class/interface/whatever it is. Also, note that this is a warning, not an error. This means, your code can compile and execute without issues.
To fix this, just remove the unused import statements.
Example of how to raise unused import:
package something;
//this interface is never used in this class
import java.util.List;
public class Example {
public static void main(String args[]) {
System.out.println("Hello world");
}
}
Example of how to fix it:
package something;
//removed import java.util.List; since it's not used
public class Example {
public static void main(String args[]) {
System.out.println("Hello world");
}
}

LoggerFactory.create() vs LoggerFactory.getLogger() - Java

I cam across the following Logger definition in my Java code and noticed that the following LoggerFactory uses the .create() method. I tried to locate good documentation to explain the difference between LoggerFactory.getLogger(getClass()) and LoggerFactory.create(getClass()) but seem to have difficulties figuring out what exactly they do differently.
The package supporting the imports is called: javautils-lib-3.0.jar.
import utils.log.ILogger;
import utils.log.Log;
import utils.log.LogLevel;
import utils.log.Logger;
import utils.log.LoggerFactory;
public static final ILogger LOG = LoggerFactory.create(LoggedExperiment.class);
Was wondering whether anyone would be able to point me in the right direction?
Have a great day.
M

SQUARE cannot be resolved to a variable in Processing/Eclipse

I have a problem with the following code:
parent.strokeCap(SQUARE);
I tried importing these:
import processing.core.PApplet;
import processing.core.PGraphics;
import processing.core.PShape;
import processing.core.PConstants;
import processing.core.PShapeSVG;
import processing.core.PGraphicsJava2D;
import processing.core.PStyle;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
But the problem persists. Do I have to make another import? I tried to find what value SQUARE represents but was unable to find any info about what it should contain.
note that you're not writing "Processing", you're writing Java, with all the regular Java formalisms and requirements, with some of your imports simply being the Processing API library. If you need a library constant, PConstants.SQUARE will get you there.

Import "imports" in eclipse - Java

I have several java files in a package and all of them have the same import blocks e.g :
package org.ezim.core;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import org.ezim.core.Ezim;
import org.ezim.core.EzimDtxSemantics;
import org.ezim.core.EzimLogger;
import org.ezim.ui.EzimFileOut;
import org.ezim.ui.EzimMain;
It looks awful having the same batches of code in each file and i want to refactor it.
I was wondering if its possible to put all these imports in a single java file then use a single line in all the other java files to call them.
Its like the extend function for classes (for variables) , but i want one for the imports.
Thanks
No. That isn't possible. What is possible is not using imports at all, instead you can use fully qualified class names like
org.ezim.core.Ezim ezim = new org.ezim.core.Ezim(); // <-- not import needed.
You can always use * sign to import multiple classes from one package, but thus watch for name clashes.

Why is my import of the containsString method not working?

I've written the simple Java script below in order to learn more about TDD, IntelliJ and Java itself.
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.both;
public class JUnit_Dummy {
private StringJoiner joiner;
private List<String> strings;
#Before
public void setUp() throws Exception {
strings = new ArrayList<String>();
joiner = new StringJoiner();
}
....
#Test
public void shouldContainBothStringsWhenListIsTwoStrings() {
strings.add("one");
strings.add("two");
assertThat(joiner.join(strings),
both(containsString("A")).
and(containsString("B")));
}
}
_____________
import java.util.List;
public class StringJoiner {
public String join(List<String> strings) {
if(strings.size() > 0) {
return (strings.get(0);
}
return "";
}
}
I'm trying to use the "containsString" method inside an assertion, but IntelliJ keeps telling me that it "cannot resolve method 'containsString(java.lang.String)". This despite the fact that the jUnit docs (http://junit.sourceforge.net/javadoc/org/junit/matchers/JUnitMatchers.html#containsString(java.lang.String)) tell me that this method does accept a String parameter.
I've tried swapping out various import statements, including the following:
import static org.hamcrest.Matcher.containsString;
import static org.hamcrest.Matcher.*;
import static org.hamcrest.CoreMatchers.*;
The best that I get is a greyed-out import statement telling me that the import statement is unused. Not sure what the problem is, any help would be appreciated.
UPDATE:
Here is the exact compiler error:
java: cannot find symbol
symbol: method containsString(java.lang.String)
location: class JUnit_Dummy
I thought I had tried every worthwhile import statement already, but this one did the trick:
import static org.junit.matchers.JUnitMatchers.*;
I faced the same issue with a Spring Boot app.
Seems like this is a dependency ordering issue.. one of the dependencies mentioned in pom.xml before the "spring-boot-starter-test" artifact was overriding the hamcrest version.
So all I did was change the order (moved this dependency up):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
I'm using Spring Boot 1.5.7.RELEASE.
We are supposed to use containsString method of hamcrest library.
My suggestion would be to stick to Junit 4 and import hamcrest library 1.3 in your build path. This would do the trick.
This will allow you to access other features of hamcrest library as well.
The solution can also be found by adding the required static imports manually. Or you can configure the required static imports in favorites tab of eclipse.
try this instead
import static org.hamcrest.CoreMatchers.*;
I'm working with MAVEN - doing a tutorial and I ran into this same issue.
I used the "import static org.hamcrest.CoreMatchers.*;" solution and that failed.
So I then moved JUNIT to be first on the list in the POM file - and that solved it.

Categories