2015-02-08 167 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