未处理的异常 java.io.iOException
Unhandled Exception java.io.iOException
我在编译时遇到未处理的异常 java.io.IOException
。我已经 post 编辑了下面的代码并指出了错误行。我搜索了很多关于这个问题的 post 但我没有找到任何相关的解决方案。
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();
}
}
}
}
您调用 startRecording()
,我假设它可以抛出 IOException
,但您没有指定 IOException
可以出现在 public void run()
中。如果你用 try-catch 块包围 startRecording()
,它应该被修复。
try {
startRecording();
}catch(IOException ex) {
//Do something with the exception
}
我在编译时遇到未处理的异常 java.io.IOException
。我已经 post 编辑了下面的代码并指出了错误行。我搜索了很多关于这个问题的 post 但我没有找到任何相关的解决方案。
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();
}
}
}
}
您调用 startRecording()
,我假设它可以抛出 IOException
,但您没有指定 IOException
可以出现在 public void run()
中。如果你用 try-catch 块包围 startRecording()
,它应该被修复。
try {
startRecording();
}catch(IOException ex) {
//Do something with the exception
}