当前位置: 代码迷 >> J2SE >> 启动,未初始化小程序,该如何解决
  详细解决方案

启动,未初始化小程序,该如何解决

热度:363   发布时间:2016-04-24 01:26:15.0
启动,未初始化小程序
本人初学Java 3D,照书敲了一段代码,结果运行的时候出现错误,小程序查看器左下角显示“启动,未初始化小程序”。
控制台显示:
Java code
java.lang.NullPointerException: Canvas3D: null GraphicsConfiguration    at javax.media.j3d.Canvas3D.checkForValidGraphicsConfig(Canvas3D.java:982)    at javax.media.j3d.Canvas3D.<init>(Canvas3D.java:1025)    at wjg.test.MyCone.<init>(MyCone.java:49)    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)    at java.lang.reflect.Constructor.newInstance(Unknown Source)    at java.lang.Class.newInstance0(Unknown Source)    at java.lang.Class.newInstance(Unknown Source)    at sun.applet.AppletPanel.createApplet(Unknown Source)    at sun.applet.AppletPanel.runLoader(Unknown Source)    at sun.applet.AppletPanel.run(Unknown Source)    at java.lang.Thread.run(Unknown Source)


程序源代码为:
Java code
package wjg.test;import java.applet.Applet;import java.awt.BorderLayout;import com.sun.j3d.utils.applet.MainFrame;import com.sun.j3d.utils.geometry.Cone;    //调用生成Cone的Utility包import com.sun.j3d.utils.geometry.Primitive;import com.sun.j3d.utils.universe.*;import javax.media.j3d.*;import javax.vecmath.*;public class MyCone extends Applet{    public BranchGroup createSceneGraph(){        BranchGroup objRoot = new BranchGroup();    //创建一个分支节点来包含一组对象        TransformGroup objTrans = new TransformGroup();        //创建转换节点(生成坐标系)        objRoot.addChild(objTrans);        //将转换节点(坐标系)添加到根节点上        BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),100.0);        //设置场景的有效范围        Color3f bgColor = new Color3f(0.0f,0.0f,0.0f);        //定义背景颜色        Background bg = new Background(bgColor);        //创建背景颜色        bg.setApplicationBounds(bounds);        objRoot.addChild(bg);         //将背景添加到场景中        Color3f directionalColor= new Color3f(1.f,1.f,1.f);        Vector3f vec = new Vector3f(0.f,0.f,-1.f);        DirectionalLight directionalLight = new DirectionalLight(directionalColor,vec);        directionalLight.setInfluencingBounds(bounds);        objRoot.addChild(directionalLight);                //设置外观        Appearance app = new Appearance();        Material material =new Material();        material.setDiffuseColor(new Color3f(1.0f,1.0f,1.0f));        app.setMaterial(material);                //生成基本的圆锥体        Cone cone = new Cone(.5f,1.0f,1,app);                //将生成的圆锥添加到场景中        objRoot.addChild(cone);                return objRoot;    }        public MyCone(){        setLayout(new BorderLayout());        Canvas3D c = new Canvas3D(null);        add("Center",c);        BranchGroup scene = createSceneGraph();        scene.compile();        SimpleUniverse u = new SimpleUniverse(c);        u.getViewingPlatform().setNominalViewingTransform();        u.addBranchGraph(scene);    }        public static void main(String[] args) {        // TODO Auto-generated method stub        new MainFrame(new MyCone(),400,300);    }}


请高手指点!!

------解决方案--------------------
MyCone.java第49行是哪一行?那行报了个空指针引用异常
------解决方案--------------------
Canvas3D c = new Canvas3D(null);
没有这个类吧 
当然报空指针错了
  相关解决方案
本站暂不开放注册!
内测阶段只得通过邀请码进行注册!
 
  • 最近登录:Sat Sep 22 00:01:29 CST 2018
  • 最近登录:Sat Sep 22 00:01:29 CST 2018
  • 最近登录:Sat Sep 22 00:01:29 CST 2018
  • 最近登录:Sat Sep 22 00:01:29 CST 2018
  • 最近登录:Sat Sep 22 00:01:29 CST 2018