I'm getting this crash exception in my google Crashes & ANRs section for my app java.lang.NullPointerException in android.util.LruCache.put
I have no idea what's wrong I do need some help please, why I do get this null pointer exception and how to fix it.
Crashes & ANRs:
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:841)
Caused by: java.lang.NullPointerException: key == null || value == null
at android.util.LruCache.put(LruCache.java:167)
at
com.b3du.im.GridAdapter.addBitmapToMemoryCache(GridAdapter.java:77)
at com.b3du.im.GridAdapter$BitmapWorkerTaskVideo.doInBackground(GridAdapter.java:218)
at com.b3du.im.GridAdapter$BitmapWorkerTaskVideo.doInBackground(GridAdapter.java:205)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
... 4 more
Code:
public void addBitmapToMemoryCache(String key, Bitmap bitmap) {
if (getBitmapFromMemCache(key) == null) {
mMemoryCache.put(key, bitmap);
}
}
public Bitmap getBitmapFromMemCache(String key) {
return mMemoryCache.get(key);
}
class BitmapWorkerTaskVideo extends AsyncTask<String, Void, Bitmap> {
private final WeakReference<ImageView> imageViewReference;
public BitmapWorkerTaskVideo(ImageView imageView) {
// Use a WeakReference to ensure the ImageView can be garbage collected
imageViewReference = new WeakReference<ImageView>(imageView);
}
// Decode image in background.
#Override
protected Bitmap doInBackground(String... params) {
final Bitmap bitmap = decodeSnapshotFromFileVideo(params[0], 100, 100);
addBitmapToMemoryCache(String.valueOf(params[0]), bitmap);
return bitmap;
}
// Once complete, see if ImageView is still around and set bitmap.
#Override
protected void onPostExecute(Bitmap bitmap) {
if (imageViewReference != null && bitmap != null) {
final ImageView imageView = imageViewReference.get();
if (imageView != null) {
imageView.setImageBitmap(bitmap);
}
}
}
public Bitmap decodeSnapshotFromFileVideo (String filepath, int reqWidth, int reqHeight) {
//Create a file, using the filepath
File file = new File (filepath);
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
ThumbnailUtils.createVideoThumbnail(file.getAbsolutePath(), MediaStore.Video.Thumbnails.MICRO_KIND);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
options.inJustDecodeBounds = false;
return ThumbnailUtils.createVideoThumbnail(file.getAbsolutePath(), MediaStore.Video.Thumbnails.MICRO_KIND);
}
public static Bitmap createVideoThumbnail (String filePath, int kind)
Create a video thumbnail for a video. May return null if the video is corrupt or the format is not supported.
So, Might be bitmap value is null. to avoid this Write your code like this:
if(bitmap != null)
{
addBitmapToMemoryCache(String.valueOf(params[0]), bitmap);
}
It's because ThumbnailUtils.createVideoThumbnail() can return null
So you will need to add check NPE for the bitmap in addBitmapToMemoryCache() method
Related
I am very close to having this work. I get a picture from the camera and store it in my SQLite database. However when I store it, I get this error. The byte array for the image is null when stored. Why? How can I fix it?
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.psa.stepbystep, PID: 16363
java.lang.NullPointerException: Attempt to get length of null array
at com.example.psa.stepbystep.Walk.writeToParcel(Walk.java:161)
at android.os.Parcel.writeParcelable(Parcel.java:1730)
at android.os.Parcel.writeValue(Parcel.java:1636)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:777)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1506)
Walk Activity contains Parcel
public Walk(Parcel in) {
this._photo = new byte[in.readInt()];
in.readByteArray(_photo);
}
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(_photo.length);
dest.writeByteArray(_photo);
}
WalkPhoto has this to convert
//Convert from bitmap to byte array
public static byte[] getBytes(Bitmap bitmap) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 0, stream);
return stream.toByteArray();
}
//Convert from byte array to bitmap
public static Bitmap getImage(byte[] image) {
return BitmapFactory.decodeByteArray(image, 0, image.length);
}
WalkPhoto also has this to store the image in the database
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
ImageView imageview = findViewById(R.id.imageView);
imageview.setImageBitmap(imageBitmap);
//Bitmap to bytes for database
byte[] photo = getBytes(imageBitmap);
DatabaseHandler mydb = new DatabaseHandler(getApplicationContext());
Walk walk = new Walk(photo);
mydb.addWalk(walk);
}
You can use "blob" to store image as mention in this post: https://stackoverflow.com/a/9357943/5455940
In above post "insertStatement_logo" is instance of SQLiteStatement class.
SQLiteStatement is subclass of SQLiteProgram class.
See links for reference.
https://developer.android.com/reference/android/database/sqlite/SQLiteStatement.html
https://developer.android.com/reference/android/database/sqlite/SQLiteProgram.html
here I'm trying to convert my image url to bitmap so that I can display in grid view. The log.d part is working fine, I succesffully get my image url in string format ady, but when comes to decodestream part it occurred error.
public class StringtoBitmap extends AsyncTask<String, String, Bitmap> {
#Override
protected void onPreExecute() {
super.onPreExecute();
}
#Override
protected void onPostExecute(Bitmap s) {
super.onPostExecute(s);
}
#Override
protected Bitmap doInBackground(String... params) {
try {
String src = params[0];
Log.d("SRC", src);
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
input.reset();
return myBitmap;
} catch (Exception e) {
System.out.println(e);
return null;
}
}
public void StringtoBitmap(String img) {
new StringtoBitmap().execute(img);
}
}
some part of android monitor result:
05-09 02:56:21.408 11585-11671/com.comma.androidapp1 E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #2
Process: com.comma.androidapp1, PID: 11585
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:841)
Caused by: java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:613)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:589)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:627)
at com.comma.androidapp1.StringtoBitmap.doInBackground(StringtoBitmap.java:39)
at com.comma.androidapp1.StringtoBitmap.doInBackground(StringtoBitmap.java:17)
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:841)
[ 05-09 02:56:21.418 1556: 1711 D/ ]
HostConnection::get() New Host Connection established 0xb86734b0, tid 1711
You are getting out of memory error ,your bitmap size is to big ,put below code to resolve out of memory error
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;
Bitmap preview_bitmap = BitmapFactory.decodeStream(is, null, options);
It is better to use libraries like Glide or Picasso for all image operations (decoding, resizing, downloading etc.):
Replace path with local folder path or server url
Dependency:
compile 'com.github.bumptech.glide:glide:3.5.2'
Code
Glide.with (context).load (path).into(imageView);
Using Glide to load bitmap into ImageView
My task is to get preview frames from camera, process them and update a TextView in my layout.I'm referring google's camera2 sample code and have managed to get frames using OnImageAvailableListener's OnImageAvailable() method, but I can't update my TextView's content in OnImageAvailable() definition(App crashes). I'm fairly new to Android programming and java. Any way to update my TextView after getting each frame.
Definition of OnImageAvailable(part of a fragment, not the CameraActivity, like google's sample):
public final ImageReader.OnImageAvailableListener mOnImageAvailableListener
= new ImageReader.OnImageAvailableListener() {
#Override
public void onImageAvailable(ImageReader reader) {
Image image = null;
try {
image = reader.acquireLatestImage();
ByteBuffer buffer = image.getPlanes()[0].getBuffer();
byte[] imageBytes = new byte[buffer.remaining()];
buffer.get(imageBytes);
final Bitmap bitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);
textView.append("a"); // crashes here
} finally {
if (image != null) {
image.close();
}
}
}
};
Crash log from Android Monitor:
03-19 13:14:12.384 13895-14107/com.example.android.camera2basic E/AndroidRuntime: FATAL EXCEPTION: CameraBackground
Process: com.example.android.camera2basic, PID: 13895
android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:6462)
at android.view.ViewRootImpl.invalidateChildInParent(ViewRootImpl.java:932)
at android.view.ViewGroup.invalidateChild(ViewGroup.java:4692)
at android.view.View.invalidateInternal(View.java:11806)
at android.view.View.invalidate(View.java:11770)
at android.view.View.invalidate(View.java:11754)
at android.widget.TextView.checkForRelayout(TextView.java:6867)
at android.widget.TextView.setText(TextView.java:4063)
at android.widget.TextView.setText(TextView.java:3921)
at android.widget.TextView.append(TextView.java:3627)
at android.widget.TextView.append(TextView.java:3617)
at com.example.android.camera2basic.Camera2BasicFragment$6.onImageAvailable(Camera2BasicFragment.java:760)
at android.media.ImageReader$ListenerHandler.handleMessage(ImageReader.java:548)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.os.HandlerThread.run(HandlerThread.java:61)
You need to put it in a runnable/thread. I'm not really versed with it but maybe this might help, but if it doesn't, I'm more than sure it's pointing in the right direction to a solution
public final ImageReader.OnImageAvailableListener mOnImageAvailableListener
= new ImageReader.OnImageAvailableListener() {
#Override
public void onImageAvailable(final ImageReader reader) {
Image image = null;
try {
image = reader.acquireLatestImage();
ByteBuffer buffer = image.getPlanes()[0].getBuffer();
byte[] imageBytes = new byte[buffer.remaining()];
buffer.get(imageBytes);
final Bitmap bitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);
YourClassNameHere.this.runOnUIThread(new Runnable() {
#Override
public void run() {
textView.append("a"); // crashes here
});
} finally {
if (image != null) {
image.close();
}
}
}
}
};
This question already has answers here:
How can I fix 'android.os.NetworkOnMainThreadException'?
(66 answers)
Closed 6 years ago.
Im new for android, I want to send notification with image.If i use image from drawable folder means i can do. But, i want to pull image from url and then send to it... I tried some code its crash my app. How to do
Anyone guide to me!
My code here:
protected static void postNotification(Intent intentAction, Context context,String msg,String url){
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intentAction, Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL);
Bitmap bitmap = new ImageDownloaderTask().doInBackground(url);
Notification notification = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.tapn)
.setContentTitle("Notification")
.setContentText(msg)
.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(bitmap))
.setContentIntent(pendingIntent)
.setDefaults(Notification.DEFAULT_SOUND)
.setAutoCancel(true)
.getNotification();
mNotificationManager.notify(R.string.notification_number, notification);
}
ImageDownloaderTask.java:
public class ImageDownloaderTask extends AsyncTask<String, Void, Bitmap> {
private Exception exception;
#Override
public Bitmap doInBackground(String... params) {
return downloadBitmap(params[0]);
}
private Bitmap downloadBitmap(String url) {
HttpURLConnection urlConnection = null;
try {
URL uri = new URL(url);
urlConnection = (HttpURLConnection) uri.openConnection();
int statusCode = urlConnection.getResponseCode();
if (statusCode != HttpStatus.SC_OK) {
return null;
}
InputStream inputStream = urlConnection.getInputStream();
if (inputStream != null) {
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
return bitmap;
}
} catch (Exception e) {
Log.d("URLCONNECTIONERROR", e.toString());
if (urlConnection != null) {
urlConnection.disconnect();
}
Log.w("ImageDownloader", "Error downloading image from " + url);
} finally {
if (urlConnection != null) {
urlConnection.disconnect();
}
}
return null;
}
protected void onPostExecute(Bitmap feed) {
// TODO: check this.exception
// TODO: do something with the feed
}
}
My logcat:
D/URLCONNECTIONERROR: android.os.NetworkOnMainThreadException
W/ImageDownloader: Error downloading image from https://www.google.com/intl/en_ALL/images/logo.gif
Thanks in advance!
yes because you try to do networking with main-thread for solving the problem you have 3 solution
use AsyncTask
use CallBack Pattern (i like this one a lot)
use vinci lightweight android library
first implement the Request on class have postNotification method (like this )
two use library like this
Vinci.base(context)
.process()
.load(uri, this);
three get bitmap from onSuccess method, that's it .
#Override
public void onSuccess(Bitmap bitmapparam) {
//bitmap is ready here
bitmapvar = bitmapparam;
}
You can't perform any network task in your main thread in latest versions of Android. You have to use AsyncTask for that.
To know more about AysncTask follow this
As before me you already know the reason behind the failure of your app bitmap operation .
You may use my code
private class LoadProfileImage extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public LoadProfileImage(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
//mImage.setBackground(result);
bmImage.setImageBitmap(result);
}}
As the answers before me clarify the cause of use problem is that you perform network task in your main thread. to know how to solve that error please take a look at this answer
but if you want to just get an image from URI you can use some of the amazing libraries that help you to that in one step my preferred one is Glide is fast and super simple to use.
I'm creating a RecyclerView to show a Grid of pictures. When selecting one of them, it should open a new activity with a transition.
I'm using Glide library to load the pictures and the transition looks awful because it reloads the picture in the new activity. So I had to save it in cache, and then use it for the transition.
I have the code, but sometimes if the picture doesn't load, it throws a Canvas RuntimeException.
This is the log:
07-03 15:19:58.633 28461-28461/jahirfiquitiva.project E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: jahirfiquitiva.project, PID: 28461
java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap#29f09d20
at android.graphics.Canvas.throwIfCannotDraw(Canvas.java:1282)
at android.view.GLES20Canvas.drawBitmap(GLES20Canvas.java:599)
at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:538)
at android.widget.ImageView.onDraw(ImageView.java:1176)
at android.view.View.draw(View.java:15239)
at android.view.View.updateDisplayListIfDirty(View.java:14175)
at android.view.View.getDisplayList(View.java:14197)
at android.view.GhostView.onDraw(GhostView.java:52)
at android.view.View.draw(View.java:15239)
at android.view.View.updateDisplayListIfDirty(View.java:14175)
at android.view.View.getDisplayList(View.java:14197)
at android.view.View.draw(View.java:14967)
at android.view.ViewGroup.drawChild(ViewGroup.java:3406)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3199)
at android.view.View.updateDisplayListIfDirty(View.java:14170)
at android.view.View.getDisplayList(View.java:14197)
at android.view.View.draw(View.java:14967)
at android.view.ViewGroup.drawChild(ViewGroup.java:3406)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3199)
at android.view.ViewOverlay$OverlayViewGroup.dispatchDraw(ViewOverlay.java:219)
at android.view.View.draw(View.java:15248)
at android.widget.FrameLayout.draw(FrameLayout.java:598)
at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2906)
at android.view.View.updateDisplayListIfDirty(View.java:14175)
at android.view.View.getDisplayList(View.java:14197)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:273)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:279)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:318)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:2536)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2352)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1982)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5891)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5289)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
This is the code to open the other activity and save the picture as cache:
private void openViewer(WallpapersAdapter.WallsHolder wallsHolder, int index, final HashMap<String, String> data) {
final Intent intent = new Intent(wallsActivity, ViewerActivity.class);
intent.putExtra("wallUrl", data.get(WallpapersActivity.WALL));
intent.putExtra("wallName", data.get(WallpapersActivity.NAME));
intent.putExtra("transitionName", ViewCompat.getTransitionName(wallsHolder.wall));
//save image from drawable
//get its path and send it to activity
Bitmap bitmap = drawableToBitmap(wallsHolder.wall.getDrawable());
//Convert to byte array and send to the other activity
Log.e("Resolution", bitmap.getWidth() + "x" + bitmap.getHeight());
try {
//Write file
String filename = "bitmap.png";
FileOutputStream stream = this.openFileOutput(filename, Context.MODE_PRIVATE);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
//Cleanup
stream.close();
bitmap.recycle();
//Pop intent
intent.putExtra("image", filename);
} catch (Exception e) {
e.printStackTrace();
}
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(
this, wallsHolder.wall, ViewCompat.getTransitionName(wallsHolder.wall));
startActivity(intent, options.toBundle());
}
public static Bitmap drawableToBitmap (Drawable drawable) {
Bitmap bitmap = null;
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
if(bitmapDrawable.getBitmap() != null) {
return bitmapDrawable.getBitmap();
}
}
if(drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); // Single color bitmap will be created of 1x1 pixel
} else {
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
}
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
drawable.draw(canvas);
return bitmap;
}
What could I do to fix this issue? Thanks in advance.
I suspect that once in a while your bitmap gets into the recycled state just before the Canvas gets a chance to draw onto it here drawable.draw(canvas);.
A quick solution should be not to call bitmap.recycle();, which is not strictly required for android >2.3.3. If you still want to reclaim this memory forcefully, you'll have to find a way to check when the bitmap is indeed no longer needed (i.e., Canvas had a chance to finish its drawing operations).
Move bitmap.recycle(); to another place in the code where this bitmap is really no longer needed.
Use this custom ImageView class
public class MyImageView extends ImageView {
public MyImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public MyImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyImageView(Context context) {
super(context);
}
#Override
protected void onDraw(Canvas canvas) {
try {
super.onDraw(canvas);
} catch (Exception e) {
Log.i(MyImageView.class.getSimpleName(), "Catch Canvas: trying to use a recycled bitmap");
}
}
}
I don't know much about canvas (I don't use animations that often) but if you don't find any way to fix this, you could try using this library instead: https://github.com/codepath/android_guides/wiki/shared-element-activity-transition
I solved by adding this:
Glide.with(activity).clear(view);
before load the image:
Glide.with(activity)
.load(imageUrl)
.apply(options)
.placeholder(R.drawable.loading_image)
.error(R.drawable.not_found)
.into(view);
See docs:
http://bumptech.github.io/glide/doc/resourcereuse.html
http://bumptech.github.io/glide/doc/resourcereuse.html#cannot-draw-a-recycled-bitmap