2011-10-08 121 views
0

问题解决!!!我已经从c:\桌面下的整个文件夹转移并出于某种原因,它正在工作java.io.FileNotFoundExceptionis抛出原因不明

我有一个非常奇怪的场景。
我试图运行我的合作伙伴的版本,这是完全正常工作,没有任何例外,他的电脑 - 这是同一个项目。
任何想法?
添加了相关的代码..

public class DJ implements Runnable 
{ 
    private static final int k_SoundLoop = 500; 
    private static final int k_NumberOfSong = 2; 
    private static final int k_CairoTrainSong = 0; 
    private static final int k_MachineSong = 1; 


    private ArrayList<Clip> m_Records = new ArrayList<Clip>(); 
    private int m_CurrentRecored = 0; 
    private Thread m_MusicThread = null; 
    private AppletContext m_AppletContext; 
    //java.net.URL m_CodeBase; 
    //AppletContext ac; 

    public DJ() 
    { 
     try 
     { 
      createClip(getClass().getResource("/Music/train.au")); 
      createClip(getClass().getResource("/Music/machine.au")); 
     } 
     catch (Exception ex) 
     { 
      Logger.getLogger(DJ.class.getName()).log(Level.SEVERE, null, ex); 
     } 

    } 

    private void createClip(URL i_SoundFileURL) throws Exception 
    { 

     File soundFile = new File(i_SoundFileURL.getFile()); 
     AudioInputStream sound = AudioSystem.getAudioInputStream(soundFile); 
     // load the sound into memory (a Clip) 
     DataLine.Info info = new DataLine.Info(Clip.class, sound.getFormat()); 
     Clip clip = (Clip) AudioSystem.getLine(info); 
     clip.open(sound); 
     m_Records.add(clip); 
    } 


    public void play() 
    { 
     m_Records.get(m_CurrentRecored).loop(k_SoundLoop); 
    } 


    public void play(int i_RecoredNumber) 
    { 
     stopCurrentClipIfNeeded(); 
     m_CurrentRecored = i_RecoredNumber; 
     m_Records.get(m_CurrentRecored).start(); 
    } 

    public void stop() 
    { 
     stopCurrentClipIfNeeded(); 
     m_CurrentRecored = 0; 
    } 

    public void stop(int i_RecordNumber) 
    { 
     m_Records.get(i_RecordNumber).stop(); 
    } 

    public void Next() 
    { 
     stopCurrentClipIfNeeded(); 
     m_CurrentRecored = ((m_CurrentRecored+1)%k_NumberOfSong); 
     m_Records.get(m_CurrentRecored).start(); 
    } 


    private void stopCurrentClipIfNeeded() 
    { 
     if (m_Records.get(m_CurrentRecored).isRunning()) 
     { 
      m_Records.get(m_CurrentRecored).stop(); 
     } 
    } 

    public boolean IsRunning() 
    { 
     return m_Records.get(m_CurrentRecored).isRunning(); 
    } 

    public void CloseRecoredSet() 
    { 
     for (Clip clip : m_Records) 
     { 
      clip.close(); 
     } 
    } 

    @Override 
    public void run() 
    { 
     m_Records.get(m_CurrentRecored).start(); 
    } 



} 

感谢

我一直得到这个:

08/10/2011 23:47:48 LogicEngine.DJ <init> 
SEVERE: null 
java.io.FileNotFoundException: C:\Users\Dan\Desktop\CairoNightTrain\CairoNightTrain\CairoNightTrainClient\src\Music\train.au (‏‏System can not find the path specified) 
     at java.io.FileInputStream.open(Native Method) 
     at java.io.FileInputStream.<init>(FileInputStream.java:106) 
     at com.sun.media.sound.WaveFileReader.getAudioInputStream(WaveFileReader.java:205) 
     at javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1162) 
     at LogicEngine.DJ.createClip(DJ.java:56) 
     at LogicEngine.DJ.<init>(DJ.java:42) 
     at GUI.JPanelGameApplet$1.run(JPanelGameApplet.java:63) 
     at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199) 
     at java.awt.EventQueue.dispatchEvent(EventQueue.java:597) 
     at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269) 
     at java.awt.EventDispatc 
+0

它就是这样说的:列表中有0个元素 – Bozho

+2

该文件存在于C:\用户\丹\桌面\ CairoNightTrain \ CairoNightTrain \ CairoNightTrainClient的\ src \音乐\ train.au他的计算机上,但不在你的身上。您可能想要显示代码。我希望文件位置不会被硬编码到程序中。 –

+0

我检查了相同的根目录没问题我有所有这些文件夹,但在我的朋友电脑上根本没有问题 – JavaSa

回答

1

C:\用户\丹\桌面\ CairoNightTrain \ CairoNightTrain \ CairoNightTrainClient的\ src \音乐\ train.au

你的朋友有没有任何机会叫丹?它找不到这个文件。我认为这很清楚?

这是什么打印?

File file = new File("/Music/train.au"); 
String absolutePathOfFile = file.getAbsolutePath(); 
System.out.println(" The absolute path is " + absolutePathOfFile); 
+0

没有它是我的 路径没有硬编码 – JavaSa

+0

你可以通过将路径复制到资源管理器窗口手动物理地打开文件吗? – FailedDev

+0

是的,我可以打开它 – JavaSa