我开始尝试Apache Pivot,因为我想用XML创建java GUI。
我在他们的网站上使用maven项目关注他们的Hello BXML tutorial。
这些是我正在使用的文件:
HelloBXML.java
package za.co.iriesoft;
import org.apache.pivot.beans.BXMLSerializer;
import org.apache.pivot.collections.Map;
import org.apache.pivot.wtk.Application;
import org.apache.pivot.wtk.Display;
import org.apache.pivot.wtk.Window;
public class HelloBXML implements Application {
private Window window = null;
public void startup(Display display, Map<String, String> properties) throws Exception {
BXMLSerializer bxmlSerializer = new BXMLSerializer();
window = (Window) bxmlSerializer.readObject(HelloBXML.class, "hello.bxml");
window.open(display);
}
public boolean shutdown(boolean optional) {
if (window != null) {
window.close();
}
return false;
}
public void suspend() {
}
public void resume() {
}
}
hello.bxml
<?xml version="1.0" encoding="UTF-8"?>
<Window title="Hello BXML!" maximized="true"
xmlns:bxml="http://pivot.apache.org/bxml"
xmlns="org.apache.pivot.wtk">
<Label text="Hello BXML!"
styles="{font:'Arial bold 24', color:'#ff0000',
horizontalAlignment:'center', verticalAlignment:'center'}"/>
</Window>
App.java
package za.co.iriesoft;
import org.apache.pivot.wtk.DesktopApplicationContext;
public class App {
public static void main(String[] args) {
DesktopApplicationContext.main(HelloBXML.class, args);
}
}
当我运行应用程序时,我得到一个例外:
Exception: An error occurred at line number 4 in file /C:/Apps/java/java-ws-client/target/classes/za/co/iriesoft/hello.bxml:
org.apache.pivot.serialization.SerializationException: An error occurred at line number 4 in file /C:/Apps/java/java-ws-client/target/classes/za/co/iriesoft/hello.bxml:
at org.apache.pivot.beans.BXMLSerializer.logException(BXMLSerializer.java:1516)
at org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:514)
at org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:684)
at org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:639)
at org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:600)
at za.co.iriesoft.HelloBXML.startup(HelloBXML.java:14)
at org.apache.pivot.wtk.DesktopApplicationContext$2.run(DesktopApplicationContext.java:666)
at org.apache.pivot.wtk.ApplicationContext$QueuedCallback.run(ApplicationContext.java:1690)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: org.apache.pivot.serialization.SerializationException: java.lang.ExceptionInInitializerError
at org.apache.pivot.beans.BXMLSerializer.processStartElement(BXMLSerializer.java:829)
at org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:493)
... 20 more
Caused by: java.lang.ExceptionInInitializerError
at org.apache.pivot.wtk.Component.installSkin(Component.java:807)
at org.apache.pivot.wtk.Window.<init>(Window.java:472)
at org.apache.pivot.wtk.Window.<init>(Window.java:467)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at org.apache.pivot.beans.BXMLSerializer.newTypedObject(BXMLSerializer.java:1697)
at org.apache.pivot.beans.BXMLSerializer.processStartElement(BXMLSerializer.java:827)
... 21 more
Caused by: org.apache.pivot.wtk.ThemeNotFoundException: A theme could not be located.
at org.apache.pivot.wtk.Theme.<clinit>(Theme.java:77)
... 31 more
org.apache.pivot.serialization.SerializationException: java.lang.ExceptionInInitializerError
at org.apache.pivot.beans.BXMLSerializer.processStartElement(BXMLSerializer.java:829)
at org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:493)
at org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:684)
at org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:639)
at org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:600)
at za.co.iriesoft.HelloBXML.startup(HelloBXML.java:14)
at org.apache.pivot.wtk.DesktopApplicationContext$2.run(DesktopApplicationContext.java:666)
at org.apache.pivot.wtk.ApplicationContext$QueuedCallback.run(ApplicationContext.java:1690)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: java.lang.ExceptionInInitializerError
at org.apache.pivot.wtk.Component.installSkin(Component.java:807)
at org.apache.pivot.wtk.Window.<init>(Window.java:472)
at org.apache.pivot.wtk.Window.<init>(Window.java:467)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at org.apache.pivot.beans.BXMLSerializer.newTypedObject(BXMLSerializer.java:1697)
at org.apache.pivot.beans.BXMLSerializer.processStartElement(BXMLSerializer.java:827)
... 21 more
Caused by: org.apache.pivot.wtk.ThemeNotFoundException: A theme could not be located.
at org.apache.pivot.wtk.Theme.<clinit>(Theme.java:77)
... 31 more
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: Could not initialize class org.apache.pivot.wtk.Theme
at org.apache.pivot.wtk.Component.installSkin(Component.java:807)
at org.apache.pivot.wtk.TextArea.<init>(TextArea.java:603)
at org.apache.pivot.wtk.ApplicationContext.defaultUncaughtExceptionHandler(ApplicationContext.java:2134)
at org.apache.pivot.wtk.ApplicationContext.handleUncaughtException(ApplicationContext.java:2155)
at org.apache.pivot.wtk.DesktopApplicationContext$2.run(DesktopApplicationContext.java:669)
at org.apache.pivot.wtk.ApplicationContext$QueuedCallback.run(ApplicationContext.java:1690)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
有人知道可能是什么问题吗?我一整天都在努力尝试不同的IDE,并在谷歌及其bug数据库中搜索答案,但无济于事。
我在Windows 10,Java SDK 1.8.0_152上运行
答案 0 :(得分:2)
我猜你的类路径中没有“pivot-wtk-terra ... jar”文件。潜在的错误似乎是“无法找到主题”。那个主题就是这个“...... terra ... jar”文件。