我用Java创建一个简单的VLCJ应用程序来播放来自JFrame的视频。运行应用程序时,我不断收到ClassNotFound
个异常。任何关于发生什么事情的线索都将非常感激。
App.java:
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import uk.co.caprica.vlcj.discovery.NativeDiscovery;
public class App {
private static JFrame mainFrame;
// media player component
private static EmbeddedMediaPlayerComponent mediaPlayerComponent;
public static void main(String[] args) {
new NativeDiscovery().discover();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new App();
}
});
}
public App() {
// initialize a jframe to frame the video we will eventually be displaying
mainFrame = new JFrame("My First Video Player");
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.setSize(500, 500);
// initialize the media player component:
mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
// add media player component onto the mainFrame
mainFrame.setContentPane(mediaPlayerComponent);
mainFrame.setVisible(true);
}
}
的pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.vismark</groupId>
<artifactId>MediaTransmitter</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MediaTransmitter</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- VLCJ dependency for video capability -->
<dependency>
<groupId>uk.co.caprica</groupId>
<artifactId>vlcj</artifactId>
<version>3.10.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.jna/jna -->
<dependency>
<groupId>com.sun.jna</groupId>
<artifactId>jna</artifactId>
<version>3.0.9</version>
</dependency>
<!-- compiler would complain at run-time about not being able to find this -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.12</version>
</dependency>
</dependencies>
错误讯息:
log4j:WARN No appenders could be found for logger (uk.co.caprica.vlcj.Info).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: com/sun/jna/platform/unix/X11$Atom
at uk.co.caprica.vlcj.player.MediaPlayerFactory.<clinit>(MediaPlayerFactory.java:175)
at uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent.onGetMediaPlayerFactory(EmbeddedMediaPlayerComponent.java:349)
at uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent.<init>(EmbeddedMediaPlayerComponent.java:217)
at com.vismark.MediaTransmitter.App.<init>(App.java:32)
at com.vismark.MediaTransmitter.App$1.run(App.java:20)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:764)
at java.desktop/java.awt.EventQueue.access$500(EventQueue.java:97)
at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:717)
at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:711)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:89)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:734)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:199)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: java.lang.ClassNotFoundException: com.sun.jna.platform.unix.X11$Atom
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
... 19 more
答案 0 :(得分:0)
检查是否找到了正确的VLCJ。 把它放在主要:
boolean found = new NativeDiscovery().discover();
System.out.println(found);
System.out.println(LibVlc.INSTANCE.libvlc_get_version());
如果VLCJ出现故障,这些行也让我有点怀疑:
Caused by: java.lang.ClassNotFoundException: com.sun.jna.platform.unix.X11$Atom
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
因为它说找不到JNA ....
如果我明白了 http://capricasoftware.co.uk/#/projects/vlcj/tutorial/logging 正确但只有
<dependency>
<groupid>uk.co.caprica</groupid>
<artifactid>vlcj</artifactid>
<version>3.10.1</version>
</dependency>
应该需要......