问题
I'm having a problem with my asynctask code. here is my code. it said that it couldn't read row 0.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
Uri filePath = data.getData();
try {
new ImageCompressionAsyncTask(getApplicationContext()).execute(String.valueOf(filePath));
} catch (Exception e) {
e.printStackTrace();
}
}
}
class ImageCompressionAsyncTask extends AsyncTask<String, Void, String> {
Context mContext;
public ImageCompressionAsyncTask(Context context){
mContext = context;
}
@Override
protected String doInBackground(String... params) {
String filePath = SiliCompressor.with(mContext).compress(params[0]);
return filePath;
}
@Override
protected void onPostExecute(String s) {
File imageFile = new File(s);
compressUri = Uri.fromFile(imageFile);
try {
bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), compressUri);
imageView.setImageBitmap(bitmap);
}
catch (IOException e) {
e.printStackTrace();
}
}
}
here is the logcat of the project.
08-01 08:32:50.181 28589-28920/ground.project.com.undergroundproject E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #5
Process: ground.project.com.undergroundproject, PID: 28589
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
at android.database.CursorWindow.nativeGetString(Native Method)
at android.database.CursorWindow.getString(CursorWindow.java:438)
at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
at android.database.CursorWrapper.getString(CursorWrapper.java:114)
at com.iceteck.silicompressorr.SiliCompressor.getRealPathFromURI(SiliCompressor.java:322)
at com.iceteck.silicompressorr.SiliCompressor.compressImage(SiliCompressor.java:163)
at com.iceteck.silicompressorr.SiliCompressor.compress(SiliCompressor.java:59)
at ground.project.com.undergroundproject.UploadPhotoActivity$ImageCompressionAsyncTask.doInBackground(UploadPhotoActivity.java:124)
at ground.project.com.undergroundproject.UploadPhotoActivity$ImageCompressionAsyncTask.doInBackground(UploadPhotoActivity.java:113)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
i have used the silicompressor library in order to compress the image i will upload in the server. but this happens. appreciate the help that i could get here. thank you guys.
来源:https://stackoverflow.com/questions/38689604/android-fatal-exception-asynctask-5