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 8619905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:27:11+00:00 2026-06-12T06:27:11+00:00

I want to convert a linearlayout to an image.I am using the following code

  • 0

I want to convert a linearlayout to an image.I am using the following code for that purpose,but i am getting nullpointerexception.Please tell me how to solve this problem.This is the code:

public class AndroidWebImage extends Activity {

ImageView bmImage; 
LinearLayout view;
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);

      view = (LinearLayout)findViewById(R.id.screen);
      bmImage = (ImageView)findViewById(R.id.image);

      view.setDrawingCacheEnabled(true);
      // this is the important code :)  
      // Without it the view will have a dimension of 0,0 and the bitmap will be null          

      view.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), 
            MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));

      view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); 

      view.buildDrawingCache(true);
      Bitmap b = Bitmap.createBitmap(view.getDrawingCache());
      view.setDrawingCacheEnabled(false); // clear drawing cache

      bmImage.setImageBitmap(b);   

};
}

I am getting exception in this line:

 Bitmap b = Bitmap.createBitmap(view.getDrawingCache());

This is the error log:

09-13 12:19:26.061: W/dalvikvm(551): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
09-13 12:19:26.112: E/AndroidRuntime(551): Uncaught handler: thread main exiting due to uncaught exception
09-13 12:19:26.593: E/AndroidRuntime(551): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.velosys.interview_preparation/com.velosys.interview_preparation.activities.Certificate}: java.lang.NullPointerException
09-13 12:19:26.593: E/AndroidRuntime(551):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
09-13 12:19:26.593: E/AndroidRuntime(551):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
09-13 12:19:26.593: E/AndroidRuntime(551):  at android.app.ActivityThread.access$2200(ActivityThread.java:119)
09-13 12:19:26.593: E/AndroidRuntime(551):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
09-13 12:19:26.593: E/AndroidRuntime(551):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-13 12:19:26.593: E/AndroidRuntime(551):  at android.os.Looper.loop(Looper.java:123)
09-13 12:19:26.593: E/AndroidRuntime(551):  at android.app.ActivityThread.main(ActivityThread.java:4363)
09-13 12:19:26.593: E/AndroidRuntime(551):  at java.lang.reflect.Method.invokeNative(Native Method)
09-13 12:19:26.593: E/AndroidRuntime(551):  at java.lang.reflect.Method.invoke(Method.java:521)
09-13 12:19:26.593: E/AndroidRuntime(551):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
09-13 12:19:26.593: E/AndroidRuntime(551):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
09-13 12:19:26.593: E/AndroidRuntime(551):  at dalvik.system.NativeStart.main(Native Method)
09-13 12:19:26.593: E/AndroidRuntime(551): Caused by: java.lang.NullPointerException
09-13 12:19:26.593: E/AndroidRuntime(551):  at android.graphics.Bitmap.createBitmap(Bitmap.java:358)
09-13 12:19:26.593: E/AndroidRuntime(551):  at com.velosys.interview_preparation.activities.Certificate.onCreate(Certificate.java:76)
09-13 12:19:26.593: E/AndroidRuntime(551):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-13 12:19:26.593: E/AndroidRuntime(551):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
09-13 12:19:26.593: E/AndroidRuntime(551):  ... 11 more
09-13 12:19:26.661: I/dalvikvm(551): threadid=7: reacting to signal 3
09-13 12:19:26.661: E/dalvikvm(551): Unable to open stack trace file '/data/anr/traces.txt': Permission denied

Thanks in advance.

  • 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-12T06:27:12+00:00Added an answer on June 12, 2026 at 6:27 am

    You can’t do this in onCreate. The layout has not yet been displayed. You can do it later in the Activity’s lifecylce, e.g. onWindowFocusChanged or use a ViewTreeObserver which I prefer as it’s more in keeping with OOP.

    http://developer.android.com/reference/android/view/ViewTreeObserver.OnGlobalLayoutListener.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to convert ivr file to mp4 using ffmpeg, but it seems ffmpeg
I want convert a File(.jpg image file) into a txt file(ASCII code) now, I
Want to convert decimal to binary but am getting some bugs. I am now
Want to convert some C# code for RX to F# code. The following C#
I want to convert a column of numbers to numeric, but there are certain
I want to convert any video to mp4(x264).But codecs of videos which will be
I want to convert an iplimage to a cv::mat (not CvMat). With this code
i want convert this c++ code in C#: RECT rcCurrent; ::GetWindowRect ( hwndChild, &rcCurrent
this jquery code works fine for me in jquery format. I want convert this
I to want convert PDF pages into an image (PNG,JPEG/JPG or GIF). I want

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.