I'm trying to run some code that imports test.x3dv
in Java. The Java code that I have is:
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);
}
}
And the code for the test.x3dv file is:
#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
When I run the code, I get the following:
Exception in thread "main" java.lang.NullPointerException
Unable to find X3D browser factory implementation
at org.web3d.x3d.sai.BrowserFactory.createX3DComponent(BrowserFactory.java:252)
at xj3dtest.Xj3DTest.<init>(Xj3DTest.java:20)
at xj3dtest.Xj3DTest.main(Xj3DTest.java:36)
I believe it's to do with the Component browserComponent = (Component) x3dComponent.getImplementation();
line and trying to call a method on a null object and I don't know how to fix it. If anyone can help, it would be greatly appreciated.
EDIT I was wondering how I'd go about trying to fix that one line so it works. That other question is useful but I'm struggling to see how I can use it for this line.