2015-02-08 168 views
1

我是新来的java,但可以找到我的方式足够做一些简单的编程。资源文件未找到

我碰到这个,我想我会尝试(使用的IntelliJ 14,Windows 8.1中,GeForce图形卡)

http://www.java2s.com/Code/Java/3D/Thisexamplecreatesa3DflyoverofthecityofBoston.htm

将所有等方面的程序编译使用javax库后,但随后下降在这种错误

java.io.FileNotFoundException: heli.obj (The system cannot find the file specified) 
Error could not load sound file: javax.media.j3d.SoundException: MediaContainer: setURL - bad URL 

这似乎是它加载文件的行

protected Group createGeometryGroup(Appearance app, Vector3d position, Vector3d scale, String szTextureFile, String szSoundFile) 
    { 
     TransformGroup tg = new TransformGroup(); 

     // we need to flip the helicopter model 
     // 90 degrees about the X axis 
     Transform3D t3d = new Transform3D(); 
     t3d.rotX(Math.toRadians(-90)); 
     tg.setTransform(t3d); 

     try 
     { 
      ///////////////////////////////////////////////////////// 
      tg.addChild(loadGeometryGroup("heli.obj", app)); 
      ///////////////////////////////////////////////////////// 

      // create an Alpha object for the Interpolator 
      Alpha alpha = new Alpha(-1, 
        Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 
        (long) Utils.getRandomNumber(0, 500), 
        (long)Utils.getRandomNumber(0, 500), 
        (long)Utils.getRandomNumber(20000, 5000), 
        4000, 
        100, 
        (long) Utils.getRandomNumber(20000, 5000), 
        5000, 
        50); 

      attachSplinePathInterpolator(alpha, 
        new Transform3D(), 
        new URL(((Java3dApplet) m_Component).getWorkingDirectory(), "d:\\flyover\\heli_spline.xls")); 
     } 
     catch(Exception e) 
     { 
      System.err.println(e.toString()); 
     } 

     return tg; 
    } 

该文件和其他一些资源位于我的src目录中,并被复制到out目录。那么,为什么程序不能找到它们,我应该在哪里放置它们以便找到它们?

我也使用URI试图 “文件:/// d:/Flyover/heli.obj”,却得到了一个“MalformedURL错误

谁能帮助

感谢 史蒂夫

回答

0

我真的不知道问题出在哪里,但我可以推测,您获得的项目是基于可执行文件将运行在特定目录(特别是heli.obj所在的目录)的假设下构建的。

他们可能是在一些自述文件中解释这个,你可能错过了。

所以,你需要离开loadGeometryGroup("heli.obj", app)原样,你需要去的IntelliJ IDEA的Run菜单,Edit Configurations...,发现在左侧树中的应用程序的配置,并指定右侧的Working Directory

+0

你是多么好的人!现在解决了问题,谢谢。 – user3466354 2015-02-08 09:41:02

+0

C - :=很高兴能有帮助。你可能想'接受'我的答案。 (如果你有足够的声望,你可能也想upvote它。) – 2015-02-08 09:45:07

+1

我接受你的答案,但因为这是我的第一个话题,我不能upvote,但感谢您的快速答复。 – user3466354 2015-02-08 09:53:45