2011-10-08 3 views
0

문제가 해결되었습니다! 나는 c : \ 아래의 바탕 화면에서 전체 폴더를 옮겼으며 어떤 이유로 그것이 작동하고있다.알 수없는 이유로 java.io.FileNotFoundException가 throw됩니다.

나는 매우 이상한 시나리오가있다.
컴퓨터에서 예외없이 완전히 작동하는 파트너 버전을 실행하려고합니다. 동일한 프로젝트입니다.
아이디어가 있으십니까? 관련 코드가 추가
..

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 \ Music \ train.au

혹시 Dan이라는 친구가 계신가요? 이 파일을 찾을 수 없습니다. 나는 그것이 꽤 명백하다라고 생각한다?

무엇이 인쇄됩니까?

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