Error when loading a javacpp and javcv - java

A few weeks ago I found this tutorial on hand gesture detection for opencv and javacv. I started using the example but kept running into the same error over and over again.
Here is the error :
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jniopencv_objdetect in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1864)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:593)
at com.googlecode.javacpp.Loader.load(Loader.java:489)
at handDectector.Handy.<init>(Handy.java:32)
at handDectector.Handy.main(Handy.java:56)
Caused by: java.lang.UnsatisfiedLinkError: no opencv_objdetect248 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1864)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:593)
at com.googlecode.javacpp.Loader.load(Loader.java:481)
I read a lot of posts online related problems online related to this issue where people found the same javacpp and javacv file. I tried doing that a couple of times, but it didn't work.
Here is the code :
package handDectector;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import org.opencv.core.Core;
import java.io.*;
import com.googlecode.javacv.*;
import com.googlecode.javacv.cpp.*;
import com.googlecode.javacpp.Loader;
public class Handy extends JFrame
{
// GUI components
private HandPanel handPanel;
public Handy()
{
super("Hand Detector");
Container c = getContentPane();
c.setLayout( new BorderLayout() );
// Preload the opencv_objdetect module to work around a known bug.
Loader.load(opencv_objdetect.class);
handPanel = new HandPanel(); // the webcam pictures and drums appear here
c.add( handPanel, BorderLayout.CENTER);
addWindowListener( new WindowAdapter() {
public void windowClosing(WindowEvent e)
{ handPanel.closeDown(); // stop snapping pics, and any drum playing
System.exit(0);
}
});
setResizable(false);
pack();
setLocationRelativeTo(null);
setVisible(true);
} // end of Handy()
// -------------------------------------------------------
public static void main( String args[] )
{
new Handy();
}
} // end of Handy class
The problem lies in the opencv_obj file not being present.
I don't have much experience with this library at all. Is it possible if anyone could help me fix the problem? I know for sure there are posts on github and stackoverflow about the same exact problem... But they all use maven. Is it possible to do it without maven?

This link gives instructions on manual installation.
However I strongly suggest you to use maven or some dependency management tool. If you insist of doing it manually then you might want to try adding all the dependencies listed in dependencies section in this link.

Related

How do I load an external jar file in a Applet?

So I am working on a project in C# but in order for me to progress I need to get my jar file to run.
This is the jar file
The jar file is a game called Runescape and if I were to double click that jar file it won't do much so I was looking at this example
Applet applet = (Applet)classLoader.loadClass("client").newInstance();
applet.setStub(stub);
applet.setSize(new Dimension(763, 504));
applet.init();
applet.start();
i.add(applet);
i.pack();
i.setDefaultCloseOperation(3);
label.setVisible(false);
Which by the looks of it takes the jar file and runs it in a Applet to give the user a visual representation of the game.
And thought it could be of help.
Now since I am a C# developer with minor Java experience I find it hard to know where to start, I have IntelliJ installed and ready to create a project but what do I need to do in order to get that jar file to run in a Applet so I can later on compile that project and use it a "client" for the game?
Running an applet from an Application is actually not that easy (and not partucally recommended).
I wrote a litte test for your jar file and run into an issue which I belive is that I am missing a proper AppletStub
import javax.swing.*;
import java.applet.Applet;
import java.awt.*;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
class appletrunner
{
public static void main(String[] args) throws Exception //This is not proper Exception handling!
{
JFrame frame = new JFrame("test");
File jar = new File("gamepack_8614663.jar");
URLClassLoader classLoader = new URLClassLoader(new URL[] {jar.toURI().toURL()}, appletrunner.class.getClassLoader());
Class<?> client = classLoader.loadClass("client");
Applet applet = (Applet)client.newInstance();
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
applet.stop();
applet.destroy();
}
});
frame.getContentPane().add(applet);
frame.pack();
frame.setVisible(true);
applet.init(); // Exception here
applet.start();
}
}
This Fails on applet.init() with a cryptic Exception (caused by the obfuscator used by runescape jar). But I think with a proper AppletStub which itself requires a AppletContext it could work.
You could try implementing a class for these interfaces and add them to the applet with addStub(). Hope this is somewhat helpfull.

VLCJ cant find plugins in normal installation

My VLC.exe works fine with a bit of lag. But my simple VLCJ code does not work.
import javax.swing.JPanel;
import com.sun.jna.NativeLibrary;
import javax.swing.JFrame;
import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;
public class VideoPanel extends JPanel {
private static final String NATIVE_LIBRARY_SEARCH_PATH = "C:/Program Files/VideoLAN/VLC";
private EmbeddedMediaPlayerComponent mediaPlayerComponent;
public VideoPanel() {
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), NATIVE_LIBRARY_SEARCH_PATH);
mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
this.add(mediaPlayerComponent);
}
public static void main(String args[]){
JFrame frame = new JFrame();
frame.add(new VideoPanel());
frame.setBounds(100, 100, 800, 450);
frame.setVisible(true);
}
}
I am using 64bit java 1.8.0_60. And I am using vlc 2.2.4 64bit on Windows 10 64bit.
My error message was this.
[00000000018bbbb0] core libvlc error: No plugins found! Check your VLC installation.
Exception in thread "main" java.lang.RuntimeException: Failed to initialise libvlc.
This is most often caused either by an invalid vlc option being passed when creating a MediaPlayerFactory or by libvlc being unable to locate the required plugins.
If libvlc is unable to locate the required plugins the instructions below may help:
In the text below represents the name of the directory containing "libvlc.dll" and "libvlccore.dll" and represents the name of the directory containing the vlc plugins...
For libvlc to function correctly the vlc plugins must be available, there are a number of different ways to achieve this:
1. Make sure the plugins are installed in the "/plugins" directory, this should be the case with a normal vlc installation.
2. Set the VLC_PLUGIN_PATH operating system environment variable to point to "".
More information may be available in the log.
at uk.co.caprica.vlcj.player.MediaPlayerFactory.(MediaPlayerFactory.java:300)
at uk.co.caprica.vlcj.player.MediaPlayerFactory.(MediaPlayerFactory.java:259)
at uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent.onGetMediaPlayerFactory(EmbeddedMediaPlayerComponent.java:349)
at uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent.(EmbeddedMediaPlayerComponent.java:217)
at VideoPanel.(VideoPanel.java:19)
at VideoPanel.main(VideoPanel.java:31)
What should I do?
This is a not uncommon problem, especially it seems on Windows platforms.
The vlcj introduction tutorial uses this code to find the native library and its plugins:
package tutorial;
import uk.co.caprica.vlcj.binding.LibVlc;
import uk.co.caprica.vlcj.discovery.NativeDiscovery;
public class Tutorial {
public static void main(String[] args) {
boolean found = new NativeDiscovery().discover();
System.out.println(found);
System.out.println(LibVlc.INSTANCE.libvlc_get_version());
}
}
This NativeDiscovery class encapsulates everything needed, including setting the VLC_PLUGIN_PATH environment variable, for the most common cases.
This is the recommended way to make sure LibVLC gets properly initialised with vlcj, so please try it.

JFreeChart Null Pointer issue

I'm just trying to run a demo of a 'simple' pie chart I found online. I'm running this in Eclipse Kepler and I keep getting,
Exception in thread "main" java.lang.NullPointerException
at org.apache.fontbox.afm.AFMParser.main(AFMParser.java:304)
when I try to run the program. I would think, considering where I got the code (linked off of a JChart site), that it would run without issue. Just trying to see if anyone can see something I can't.
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;
public class BarChartDemo {
public static void main(String[] args){
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("Category 1", 50.0);
dataset.setValue("Category 2", 50.0);
JFreeChart chart = ChartFactory.createPieChart(
"Sample Pie Chart",
dataset,
true,
true,
false
);
ChartFrame frame = new ChartFrame("First",chart);
frame.pack();
frame.setVisible(true);
}
}
I was able to get the chart to appear without changing your code. Did you include both jars (jfreechart, jcommons) in your build path?
After some battling and researching (guessing), I came across this class via some Adobe Font Metrics googling. Incidentally I can't remember exactly where I found it, but it solved my issue. I'll spare the SO servers and not post the 1000(+)-line code, but here it is as a gist if anyone has the same problem. I just included it in my project source file as a separate class, and voila...
I'm still not sure why my project wouldn't run without this. It worked on other systems, but not my Eclipse Kepler (Mac OS 10.9). If anyone can tell me exactly why it kept failing, I'd be very thankful.

How to use acm.jar in eclipse?

I am learning Java by Stanford's Programming methodology videos on YouTube and I'm using the latest version of eclipse not the Stanford version. After I add acm.jar to the build path I still get a red underline under GLabel and error messages. This is what I've got:
import acm.program.*;
public class Artistry extends GraphicsProgram {
public void run() {
add(new GLabel("hello, world"), 100, 75);
}
}
Does anyone have any idea how to fix this? I really appreciate any help. Thanks :)
its because you also need to add: import acm.graphics.GLabel;
-or-
if you're going to use other G[something] you can add: import acm.graphics.*;

Error: cant find main class

I am a newbie java dev using netbeans IDE 7.1.1 and im watching this tutorial and right off the bat i get an error in my program even after 5 retypes to make sure its exactly the same as in the video so anyways this is the error
Error: Could not find or load main class javagame.JavaGame Java
Result: 1
and this is the code i have written
package JavaGame;
import javax.swing.JFrame;
public class JavaGame extends JFrame {
public JavaGame(){
setTitle("java game");
setSize(500, 500);
setResizable(false);
setVisible(true);
//setDefaultCloseOperation();
}
public static void main(String[] args){
}
}
You can find in this image how my project structure looks.
If that is an exactly copy-paste from your code, then your problem is with package name. Java is case sensitive and your package name is JavaGame so the qualified name of your class is JavaGame.JavaGame whilst the exception you get says that it can not find the class javagame.JavaGame.
Rename your package using Netbeans from JavaGame to javagame. That should fix the problem.
The problem is with your package name.. change the code at line1
package JavaGame;
package javagame;
NetBeans usually likes to use lower text for packages.
Hope this solves the problem. As the code runs on my machine.
Phil
Go to environmental variables and add path of JDK.
I got this error in past, and solved by setting classpath.

Categories