Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7827057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:42:14+00:00 2026-06-02T09:42:14+00:00

edit: Nevermind, got it working that way TopRatedPage.setDrawingCacheEnabled(true); TopRatedPage.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); TopRatedPage.layout(0, 0,

  • 0

edit:

Nevermind, got it working that way

TopRatedPage.setDrawingCacheEnabled(true);
TopRatedPage.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
TopRatedPage.layout(0, 0, TopRatedPage.getMeasuredWidth(), TopRatedPage.getMeasuredHeight()); 
TopRatedPage.buildDrawingCache(true);
Bitmap screenshot = Bitmap.createBitmap(TopRatedPage.getDrawingCache());
TopRatedPage.setDrawingCacheEnabled(false);

old:

I’m trying to take a screenshot from a layout, like so.

LinearLayout TopRatedPage = (LinearLayout)inflater.inflate(R.layout.toprated, null);
...
Bitmap screenshot;
TopRatedPage.setDrawingCacheEnabled(true);
screenshot = Bitmap.createBitmap(TopRatedPage.getDrawingCache()); // Caused by: java.lang.NullPointerException
TopRatedPage.setDrawingCacheEnabled(false);

Any ideas what I have done wrong?

Thanks!

edit:
also tried like this, it doesn’t throw an error, but given an empty bitmap.

Bitmap screenshot = TopRatedPage.getDrawingCache();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T09:42:19+00:00Added an answer on June 2, 2026 at 9:42 am

    Try this and let me know what happen..

    LinearLayout TopRatedPage = (LinearLayout)inflater.inflate(R.layout.toprated, null);
    Bitmap screenshot = Bitmap.createBitmap(LinearLayout .getWidth(), LinearLayout .getHeight(), Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(screenshot);
    LinearLayout.draw(c);
    imageView.setImageBitmap(screenshot);
    

    Also if possible, use,

    View captureView = null;
    captureView = inflater.inflate(R.layout.toprated, null);
    Bitmap screenshot = Bitmap.createBitmap(captureView.getWidth(), captureView.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(screenshot);
    captureView .draw(c);
    imageView.setImageBitmap(screenshot);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

-edit- nevermind, i made a mistake in my select statement. Update was working correctly.
** EDIT ** Nevermind, just needed to take out the parens... I get this
Edit: Translated I have a RSS-feed that i want to parse. It's a podcast
-edit- nevermind. I ran the code again and it appears i cant log into
Edit: nevermind, figured it out, answer below if you're interested. Using Postgresql 8.4. Here's
I've got AdMob working in my app, but it's showing up at the bottom
I am totally confused right now. Edit: Okay, nevermind. The Python socket as well
-edit- nevermind i was lucky and didnt need to change much and have this
EDIT: Nevermind, found duplicate after searching for a completely unrelated topic (kinda serendipitous) Probably
EDIT How to simplify the following code: if(x(a) > x(b)) s = b; e

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.