question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NullPointerException

See original GitHub issue

Hello,

I’m receiving this issue from fabric crashlytics. I am using version “2.2.6”. I cannot trace the issue myself and only have reports from crashlytics about it.

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.graphics.Bitmap.isRecycled()' on a null object reference
       at com.qozix.tileview.graphics.BitmapRecyclerDefault.recycleBitmap(Unknown Source)
       at com.qozix.tileview.tiles.Tile.reset(Unknown Source)
       at com.qozix.tileview.tiles.TileRenderRunnable.renderTile(Unknown Source)
       at com.qozix.tileview.tiles.TileRenderRunnable.run(Unknown Source)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
       at java.lang.Thread.run(Thread.java:776)

It seems that the bitmap object passed to recycleBitmap method in BitmapRecyclerDefault class is null. So when calling if( !bitmap.isRecycled() ) it produces NullPointerException.

public class BitmapRecyclerDefault implements BitmapRecycler {
  @Override
  public void recycleBitmap( Bitmap bitmap ) {
    if( !bitmap.isRecycled() ) {
      bitmap.recycle();
    }
  }
}

Any help would be greatly appreciated.

Thanks!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
dilarakklcommented, Jul 6, 2017

That must be the issue. We might call recycle in few places, I will check them. Thank you so much for the quick response! Have a nice day.

1reaction
p-lrcommented, Jul 6, 2017

After analysis, a Tile object is only given a reference to a Bitmap object in the Tile.generateBitmap method :

void generateBitmap( Context context, BitmapProvider bitmapProvider ) {
    if( mBitmap != null ) {
      return;
    }
    mBitmap = bitmapProvider.getBitmap( this, context );
    ...

So if the BitmapProvider --or any other object involved (which is implemented user side) recycles the Bitmap between the null check and the BitmapRecycler.recycleBitmap() call (in Tile.reset(), we’ve got a NullPointerException.

As a consequence, i think the fix would be to add a try catch in the BitmapRecyclerDefault. But, to fix your issue quickly, you can set your own BitmapRecycler like this :

tileView.setBitmapRecycler(new BitmapRecycler() {
   @Override
    public void recycleBitmap(Bitmap bitmap) {
       try {
          if( !bitmap.isRecycled() ) {
             bitmap.recycle();
          }
       } catch (NullPointerException e) {
       }
   }
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

NullPointerException (Java Platform SE 7 ) - Oracle Help Center
Thrown when an application attempts to use null in a case where an object is required. These include: ... Applications should throw instances...
Read more >
java - What is a NullPointerException, and how do I fix it?
NullPointerException s are exceptions that occur when you try to use a reference that points to no location in memory ...
Read more >
Null Pointer Exception In Java - GeeksforGeeks
NullPointerException is a RuntimeException. In Java, a special null value can be assigned to an object reference. NullPointerException is thrown ...
Read more >
Java NullPointerException - Detect, Fix, and Best Practices
NullPointerException is a runtime exception, so we don't need to catch it in the program. NullPointerException is raised in an application ...
Read more >
Preventing NullPointerException - Wikibooks, open books for ...
NullPointerException is a RuntimeException . In Java, a special null value can be assigned to an object reference. NullPointerException is thrown when an ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found