Fatal signal 11 when trying to use AsyncTask
I have been trying all day to solve this problem, I am trying to call the following:
new DownloadandSaveAsync(Activity_picture.this).execute(image_url);
this is called when the ImageView is clicked.
But as soon as my AsyncTask starts loading it, it just closes, no crash reporting, just the following:
Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 6744 (AsyncTask #4)
Here's my activity where I am calling it:
public class Activity_picture extends ActionBarActivity {
public static final int ALBUM_RESULT = 300;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_picture);
final String image_url = getIntent().getStringExtra("image_url");
String image_title = getIntent().getStringExtra("image_title");
ImageView picture = (ImageView) findViewById(R.id.picture);
TextView pictureTitle = (TextView) findViewById(R.id.pictureTitle);
Picasso.with(getApplicationContext()).load(image_url).into(picture);
pictureTitle.setText(image_title);
picture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new DownloadandSaveAsync(Activity_picture.this)
.execute(image_url);
finish();
}
});
}
}
And this is my AsyncTask code:
public class DownloadandSaveAsync extends AsyncTask<String, String, String> {
private ProgressDialog pDialog;
Bitmap profPictBitmap;
Context context;
URL image_value;
public DownloadandSaveAsync(Context context) {
this.context = context;
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
pDialog = new ProgressDialog(context);
pDialog.setMessage("Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
try {
image_value = new URL(params[0]);
System.out.println(image_value);
profPictBitmap = BitmapFactory.decodeStream(image_value
.openConnection().getInputStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
File f = new File(context.getCacheDir(), "profileImage");
try {
f.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Convert bitmap to byte array
Bitmap bitmap = profPictBitmap;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 0 /* ignored for PNG */, bos);
byte[] bitmapdata = bos.toByteArray();
// write the bytes in file
FileOutputStream fos = null;
try {
fos = new FileOutputStream(f);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
fos.write(bitmapdata);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Intent newIntent = new Intent(context, FeatherActivity.class);
newIntent.setData(Uri.parse(f.toString()));
newIntent.putExtra(Constants.EXTRA_IN_API_KEY_SECRET,
"SECRET KEY");
((Activity) context).startActivityForResult(newIntent, 1);
if (pDialog != null) {
if (pDialog.isShowing()) {
pDialog.dismiss();
}
}
}
}
I am 100% sure that the url being executed is not bad because I did System.out.println(image_value);
and returned the correct url like you are in the AsyncTask class.
I am calling this same AsyncTask code elsewhere in my image loading application and it works 100% fine passing other urls to it, but for some strange reason I can't figure out that it closes this error.
If anyone can help me it would be greatly appreciated! Thank you in advance.
source to share
No one has answered this question yet
Check out similar questions: