我正在写一些代码,我在四条不同的行上遇到错误,说包不存在。错误在第7行到第10行,即包org.web3d.x3d.sai不存在。我对这个项目的代码是:
package xj3dtest;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import javax.swing.JFrame;
import org.web3d.x3d.sai.Browser;
import org.web3d.x3d.sai.BrowserFactory;
import org.web3d.x3d.sai.X3DComponent;
import org.web3d.x3d.sai.X3DScene;
public class Xj3DTest extends JFrame {
public Xj3DTest(String title) {
super(title);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
X3DComponent x3dComponent = BrowserFactory.createX3DComponent(null);
Browser browser = x3dComponent.getBrowser();
Component browserComponent = (Component) x3dComponent.getImplementation();
Container cp = getContentPane();
cp.setLayout(new BorderLayout());
cp.add(browserComponent, BorderLayout.CENTER);
X3DScene scene = browser.createX3DFromURL(new String[] {"test.x3dv"});
browser.replaceWorld(scene);
}
public static void main(String[] args) {
Xj3DTest frame = new Xj3DTest("Xj3D test");
frame.setSize(640, 480);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
test.x3dv的代码是:
#X3D V3.0 utf8
PROFILE Interactive
DEF TS TimeSensor {
cycleInterval 3
loop TRUE
}
DEF TG Transform {
rotation 0 1 0 0
children Shape {
geometry Box {}
appearance Appearance {
material DEF MAT Material {
diffuseColor 1 0 0
}
}
}
}
DEF OI OrientationInterpolator {
key [ 0 0.5 1 ]
keyValue [
0 1 0 0
0 1 0 3.14
0 1 0 6.28
]
}
ROUTE TS.fraction_changed TO OI.set_fraction
ROUTE OI.value_changed TO TG.rotation
我之所以做这个小项目是因为我需要通过Java项目显示.x3d文件。我将-Xmx450M -Djava.library.path='F:\Uni\Uni work\Year Three\xj3d-code-12559-trunk\bin'
放在项目属性VM选项中,并将所有x3d jars
放在名为Xj3D
的库中。我已经通过Google搜索和第一个链接下载了org.web3d.x3d.sai
,我已将它放在我在Netbeans中创建的JARS lib文件夹中。但我仍然得到错误。
我知道昨天我问了同样的问题,但发现格式不正确,我觉得它没有表达我想要的清楚。
编辑
当我现在运行代码时,在库中获取正确的JARS后,是:
Exception in thread "main" java.lang.NullPointerException
at org.web3d.x3d.sai.BrowserFactory.createX3DComponent(BrowserFactory.java:252)
at xj3dtest.Xj3DTest.<init>(Xj3DTest.java:20)
at xj3dtest.Xj3DTest.main(Xj3DTest.java:36)