这是java程序
import java.applet.Applet;
import java.awt.Frame;
import java.io.FileNotFoundException;
import java.net.MalformedURLException;
import java.net.URL;import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.DirectionalLight;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3f;import com.sun.j3d.loaders.IncorrectFormatException;
import com.sun.j3d.loaders.ParsingErrorException;
import com.sun.j3d.loaders.Scene;
import com.sun.j3d.loaders.vrml97.VrmlLoader;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.SimpleUniverse;public class hello extends Applet
{
@Override
public void init() {
// TODO Auto-generated method stub
super.init();

} @Override
public void start() {
SimpleUniverse a=new SimpleUniverse();
BranchGroup d=new BranchGroup();
/*Sphere s=new Sphere(0.5f);
d.addChild(s);*/
VrmlLoader l=new  VrmlLoader();
    Scene sc = null;
    try {
         
URL lin=this.getClass().getClassLoader().getResource("viewswitch.wrl");
    
  System.out.print(lin.toString());
      sc = l.load(lin);
    }
    catch (FileNotFoundException e) {
 System.err.println(e);
 System.exit(1);
    }
    catch (ParsingErrorException e) {
 System.err.println(e);
 System.exit(1);
    }
    catch (IncorrectFormatException e) {
 System.err.println(e);
 System.exit(1);
    }
    //sceneTG.addChild(f);
  d.addChild(sc.getSceneGroup());
 Color3f light=new Color3f(1.0f,1.0f,1.0f);
 BoundingSphere t=new BoundingSphere(new Point3d(0.0,0.0,0.0),100.0);
 Vector3f f=new Vector3f(4.0f,-4.0f,-12.0f);
 DirectionalLight e=new DirectionalLight(light,f);
e.setInfluencingBounds(t);
d.addChild(e);
a.getViewingPlatform().setNominalViewingTransform();
a.addBranchGraph(d);
}

}
这是jsp:body>
 
    <applet alt="dfs" code="hello.class" ARCHIVE="vrml97.jar"  width=256 height=256></applet>
  </body>
</html>

解决方案 »

  1.   

    异常是:
    java.net.MalformedURLException: no protocol: ./
    at java.net.URL.<init>(Unknown Source)
    at java.net.URL.<init>(Unknown Source)
    at java.net.URL.<init>(Unknown Source)
    at com.sun.j3d.loaders.vrml97.impl.Loader.setWorldURL(Loader.java:241)
    at com.sun.j3d.loaders.vrml97.VrmlLoader.load(VrmlLoader.java:105)
    at hello.<init>(hello.java:35)
    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.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$000(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
    Exception loading URL: java.lang.NullPointerException
    java.lang.NullPointerException
    at com.sun.j3d.loaders.vrml97.impl.Loader.openURL(Loader.java:262)
    at com.sun.j3d.loaders.vrml97.impl.Loader.load(Loader.java:293)
    at com.sun.j3d.loaders.vrml97.VrmlLoader.doLoad(VrmlLoader.java:112)
    at com.sun.j3d.loaders.vrml97.VrmlLoader.load(VrmlLoader.java:106)
    at hello.<init>(hello.java:35)
    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.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$000(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
    com.sun.j3d.loaders.ParsingErrorException
    java.lang.reflect.InvocationTargetException
    at com.sun.deploy.util.DeployAWTUtil.invokeAndWait(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager.runOnEDT(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.security.AccessControlException: access denied (java.lang.RuntimePermission exitVM.1)
    at java.security.AccessControlContext.checkPermission(Unknown Source)
    at java.security.AccessController.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkExit(Unknown Source)
    at java.lang.Runtime.exit(Unknown Source)
    at java.lang.System.exit(Unknown Source)
    at hello.<init>(hello.java:43)
    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.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$000(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
    异常:java.lang.reflect.InvocationTargetException
      

  2.   

    兄弟,抛出这一异常指示出现了错误的 URL。或者在规范字符串中找不到任何合法协议,或者无法分析字符串。
    有可能是制定了未知的协议。
      

  3.   

    先確定是執行到哪句時報錯
    應該在start() VrmlLoader
      

  4.   

    URL lin=this.getClass().getClassLoader().getResource("viewswitch.wrl")
    难道这个有问题 楼主先试一试简单的applet签入保证 applet能够正确引用
      

  5.   

    我试了用这个就行
    <applet alt="dfs" code="SimplePick.class"  width=256 height=256></applet>
    但是SimplePick.class没有URL lin=this.getClass().getClassLoader().getResource("viewswitch.wrl")