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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:12:54+00:00 2026-06-04T10:12:54+00:00

I am working on a application where i need to draw and save that

  • 0

I am working on a application where i need to draw and save that as image in sd card

 public void onClickSave()
        {

            FrameLayout v = (FrameLayout) findViewById(R.id.main_frame);
            v.setDrawingCacheEnabled(true);

            v.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
            v.layout(0, 0, v.getWidth(), v.getHeight());
            v.buildDrawingCache(true);
            Bitmap bm = Bitmap.createBitmap(v.getDrawingCache());
            v.setDrawingCacheEnabled(false);
            if (bm != null) {
                try {
                    String path = Environment.getExternalStorageDirectory().toString();
                    OutputStream fOut = null;
                    File file = new File(path, "screentest.jpg");
                    fOut = new FileOutputStream(file);
                    bm.compress(Bitmap.CompressFormat.JPEG, 85, fOut);
                    fOut.flush();
                    fOut.close();                     
                }
                catch (Exception e) {
                    e.printStackTrace();
                    Toast.makeText(getContext(), e.toString(),1000).show();
                }
            }

and the function call occurs here

 Button btn_save=(Button) findViewById(R.id.button3);
        btn_save.setOnClickListener(new OnClickListener() 
        {

            public void onClick(View v) 
            {
                // TODO Auto-generated method stub

                drawView.onClickSave();

            }
        });

and i got the error in log as :

05-23 12:46:25.413: W/dalvikvm(669): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
05-23 12:46:25.423: E/AndroidRuntime(669): FATAL EXCEPTION: main
05-23 12:46:25.423: E/AndroidRuntime(669): java.lang.NullPointerException
05-23 12:46:25.423: E/AndroidRuntime(669):  at com.page2.DrawView.onClickSave(DrawView.java:173)
05-23 12:46:25.423: E/AndroidRuntime(669):  at com.page2.Draw$3.onClick(Draw.java:60)
05-23 12:46:25.423: E/AndroidRuntime(669):  at android.view.View.performClick(View.java:2408)
05-23 12:46:25.423: E/AndroidRuntime(669):  at android.view.View$PerformClick.run(View.java:8816)
05-23 12:46:25.423: E/AndroidRuntime(669):  at android.os.Handler.handleCallback(Handler.java:587)
05-23 12:46:25.423: E/AndroidRuntime(669):  at android.os.Handler.dispatchMessage(Handler.java:92)
05-23 12:46:25.423: E/AndroidRuntime(669):  at android.os.Looper.loop(Looper.java:123)
05-23 12:46:25.423: E/AndroidRuntime(669):  at android.app.ActivityThread.main(ActivityThread.java:4627)
05-23 12:46:25.423: E/AndroidRuntime(669):  at java.lang.reflect.Method.invokeNative(Native Method)
05-23 12:46:25.423: E/AndroidRuntime(669):  at java.lang.reflect.Method.invoke(Method.java:521)
05-23 12:46:25.423: E/AndroidRuntime(669):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-23 12:46:25.423: E/AndroidRuntime(669):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-23 12:46:25.423: E/AndroidRuntime(669):  at dalvik.system.NativeStart.main(Native Method)

and my xml is

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@android:color/white" >
<FrameLayout
 android:id="@+id/main_frame"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:background="@android:color/white" android:layout_weight="0.1">

<ImageView
     android:id="@+id/imageView1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
      /> 

</FrameLayout>
<RelativeLayout
 android:id="@+id/relativeLayout1"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
   android:layout_weight="0.9" android:layout_gravity="bottom" android:layout_marginTop="-10dp">
 <Button
     android:id="@+id/button2"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentBottom="true"
     android:layout_alignParentTop="true"
     android:layout_centerHorizontal="true"
     android:text="Redo" />
 <Button
     android:id="@+id/button1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentBottom="true"
     android:layout_alignParentLeft="true"
     android:layout_alignParentTop="true"
     android:text="Undo" />
 <Button
     android:id="@+id/button3"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentBottom="true"
     android:layout_alignParentRight="true"
     android:layout_alignParentTop="true"
     android:text="Save" />
 </RelativeLayout>
</LinearLayout>This is my xml 

Give me some other way of storing canvas draw as image in sd card
My app force closed when i clicked Save Button please help me
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-04T10:12:55+00:00Added an answer on June 4, 2026 at 10:12 am

    I would supsect

           FrameLayout v = (FrameLayout) findViewById(R.id.main_frame);
    

    to return null

    Check this using a debugger or logging

    When your view does not contain a FrameLayout it is either

    • not created by your xml
    • or “main_frame” has been deleted in an other function

    if this code is really at line 173

      public void onClickSave()
    

    than this is very suspect, because there is no access to a reference.
    This may be a hint of outdating the code and the apk. Try to rebuild the project
    (project->clean on eclipse)

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

Sidebar

Related Questions

A brief background: I'm working on a web-based drawing application and need to draw
I'm working on a web application that need to allow the user to drag
Currently, I am working on a web application that uses draw2d library to draw
I'm working on an application that has need of a form that allows the
I'm working on an application that will need to pull from a list of
I'm working on an application that I need to be cross-platform. I'd like to
I'm working on an application that uses Raphael to draw primitive shapes (rectangles, ellipses,
I am working on an application where I need to integrate the search engine.
I am working on an application where i need to place a uiscrollview within
I am currently working in an application where I need to find all occurrences

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.