I want to put my function in AsyncTask, but It cause error when I do it. Here is my code:
@Override
public void onClick(final View v) {
// TODO Auto-generated method stub
switch (v.getId())
{
case R.id.btnCreateVideo:
{
MP4VideoParams mParams = new MP4VideoParams(v.getContext(), "mnt/sdcard/out.mp4", "MOBILE");
new MyMP4VideoCreator().execute(mParams);
}
break;
default:
{
Toast.makeText(this, "Nothing", Toast.LENGTH_SHORT).show();
}
}
}
An my AsyncTask is simple:
private class MyMP4VideoCreator extends AsyncTask<MP4VideoParams, Void, Void> {
@Override
protected Void doInBackground(MP4VideoParams... MP4Video) {
// TODO Auto-generated method stub
try {
CreateMP4Video.CreateVideo(MP4Video[0].getContext(), MP4Video[0].getOutput(), MP4Video[0].getQuality());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}
The LogCat:
java.lang.RuntimeException: An error occured while executing doInBackground()
Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
This is my first time using AsyncTask, please help me. Thank you in advance.