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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:41:17+00:00 2026-06-03T19:41:17+00:00

I am taking a screenshot of a RelativeLayout but it cause the error. error:

  • 0

I am taking a screenshot of a RelativeLayout but it cause the error.

error:

 05-10 17:43:44.249: ERROR/AndroidRuntime(7721): Caused by: java.lang.NullPointerException
05-10 17:43:44.249: ERROR/AndroidRuntime(7721):     at android.graphics.Bitmap.createBitmap(Bitmap.java:358)
05-10 17:43:44.249: ERROR/AndroidRuntime(7721):     at com.API.Connect.share(FacebookConnect.java:110)

code:

public class Connect extends Activity implements LoginListener {

    public static String news = " ";

    RelativeLayout bitmapimage;

    Bitmap bitmap;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.image);
        bitmapimage = (RelativeLayout) findViewById(R.id.bitmapimg);
        TextView txtlove = (TextView) findViewById(R.id.txtlove);
        txtlove.setText(news.toString());
        share();

    }

    public void share() {

        View v1 = bitmapimage;
        v1.setDrawingCacheEnabled(true);

        bitmap = Bitmap.createBitmap(v1.getDrawingCache());

        v1.setDrawingCacheEnabled(false);

        saveImage();

        // TODO Auto-generated method stub

    }

    void saveImage() {
        String state = Environment.getExternalStorageState();
        Environment.MEDIA_MOUNTED.equals(state);

        File myDir = new File("/mnt/sdcard/DCIM/Camera");
        myDir.mkdirs();

        String fname = "mytry.jpg";
        File file = new File(myDir, fname);
        if (file.exists())
            file.delete();
        try {
            FileOutputStream out = new FileOutputStream(file);
            // create a Bitmap object from our image path.
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
            out.flush();
            out.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
  • 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-03T19:41:18+00:00Added an answer on June 3, 2026 at 7:41 pm

    What you are trying to do is correct. But in onCreate() your view wouldn’t have drawn. It’s just inflated. So you might have to consider using the below method. try this out.

    @Override 
    public void onWindowFocusChanged(boolean hasFocus) 
    { 
         super.onWindowFocusChanged(hasFocus);
        share();  //Call your share() here. 
    }
    

    This method gets called once your view is drawn, and hence you will be able to get the bitmap by overriding this method.

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

Sidebar

Related Questions

I am currently building this Android application, where I will be taking a screenshot
I'm taking a screenshot using this line screen = QPixmap.grabWindow(QApplication.desktop().winId()) but apparently that doesn't
I have a method where I'm taking a screenshot, but there's 2 problems with
I'm trying to take a screenshot of my Android application using Robotium, I'm using
I have this code for taking a screenshot; how could I change it to
I've been trying to code a simple screenshot application using rococoa (java to osx
in my iPad app, I'd like to make a screenshot of a UIView taking
How can I create pdf from html without taking screenshot or image of uiwebview
I am using a Java applet to take a screenshot of the web browser,
I am having problem in taking a screenshot with specific area. I have a

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.