2015-06-02 166 views
1

在编译时,我得到未处理的异常java.io.IOException。我已经发布了下面的代码并指出了错误行。我搜索了很多关于这个问题的帖子,但我没有得到任何相关的解决方案。未处理的异常java.io.iOException

MainActivity.java:

public class MainActivity extends Fragment { 

@Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { 

................... 
} 

public void startRecording() throws IOException { 

.................. 
} 

player.setOnCompletionListener(new OnCompletionListener() { 

    public void onCompletion(MediaPlayer mp) { 

     if (RecordFile != null && ifexist.equals("true")) { 
     }            
     else { 
      if (isRecclicked == true) { 
       recordButtonPressed = true; 

      try { 
       new Timer().schedule(new TimerTask() { 
        @Override 
        public void run() { 
         // this code will be executed after 2 seconds 

         startRecording(); ----> Unhandled Exception java.io.iOException 
        } 
       }, 2000); 
      } 
      catch (IOException e) { 
       e.printStackTrace(); 
      } 
     } 
    } 
} 
+0

放码。它的崩溃那边 –

+0

@PreethiRao中的startRecording没有崩溃()method.its编译errror –

+0

@ steve1显示的startRecording()method..if没有必要IOException异常即可。 ..try从抛出异常抛出IOException,或者你可以把IO语句放在try catch块下而不是抛出IOException异常...实际上抛出异常并且不处理活动 –

回答

6
try { 
     startRecording(); 
    }catch(IOException ex) { 
    //Do something with the exception 
} 
1

你叫startRecording(),我认为它,可以抛出IOException,但你没有指定一个IOException可以在里面public void run()发生。如果你用一个try-catch块包围startRecording(),它应该是固定的。的startRecording的