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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:18:25+00:00 2026-06-18T04:18:25+00:00

I am making a drawing app and would like to share the image. However,

  • 0

I am making a drawing app and would like to share the image. However, I meet an error for the startActivity part, of which the error writes The method startActivity(Intent) is undefined for the type . What does it means and how could it be tackled? Many thanks in advances!!!

EDIT:

posted further code settings for the codes: ActivityA Calling shareImage() in PaintView.

I am not sure whether the Context in this way is ok? Except this newly added sharing function, the code without sharing runs very smoothly.

PaintView

// the main screen that is painted
public class PaintView extends View 
{      
   Context context_new;       
   private boolean isFileAlreadySaved = false;
   String savedFilePath = "";

   private static final float TOUCH_TOLERANCE = 10;
   // other declarations here

   // PaintView constructor initializes the PaintView
   public PaintView(Context context, AttributeSet attrs) 
   {
      super(context, attrs); // pass context to View's constructor
      this.context_new=context;
      paintScreen = new Paint(); // used to display bitmap onto screen

      // set the initial display settings for the painted line
      paintLine = new Paint();
      paintLine.setAntiAlias(true); // smooth edges of drawn line
      paintLine.setColor(Color.BLACK); // default color is black
      paintLine.setStyle(Paint.Style.STROKE); // solid line
      paintLine.setStrokeWidth(5); // set the default line width
      paintLine.setStrokeCap(Paint.Cap.ROUND); // rounded line ends
      pathMap = new HashMap<Integer, Path>();
      previousPointMap = new HashMap<Integer, Point>();
   } // end DoodleView constructor


   public void shareImage()
   {
        Intent share;
        File attachment = null;

        if(isFileAlreadySaved == true)
        {
            attachment = new File(savedFilePath);
            boolean isFileThere = attachment.exists();
            if (isFileThere == true)
            {
                share = new Intent(Intent.ACTION_SEND);
                share.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(attachment));
                share.setType("image/png");
                startActivity(Intent.createChooser(share, "Share drawing"));
            }
        }
        else
        {
            Toast.makeText(getContext(), "Please save the image first...", Toast.LENGTH_LONG).show();    
        };
   };

ActivityA:

   public OnClickListener shareButtonListener = new OnClickListener()   
   {
      @Override
      public void onClick(View v) 
      {        
        vibrate();
        PaintView.shareImage(ActivtyA.this);
      };
   };

Logcat:

02-02 16:01:58.230: E/AndroidRuntime(9809):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
02-02 16:01:58.230: E/AndroidRuntime(9809):     at android.app.ActivityThread.access$600(ActivityThread.java:127)
02-02 16:01:58.230: E/AndroidRuntime(9809):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
02-02 16:01:58.230: E/AndroidRuntime(9809):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-02 16:01:58.230: E/AndroidRuntime(9809):     at android.os.Looper.loop(Looper.java:137)
02-02 16:01:58.230: E/AndroidRuntime(9809):     at android.app.ActivityThread.main(ActivityThread.java:4511)
02-02 16:01:58.230: E/AndroidRuntime(9809):     at java.lang.reflect.Method.invokeNative(Native Method)
02-02 16:01:58.230: E/AndroidRuntime(9809):     at java.lang.reflect.Method.invoke(Method.java:511)
02-02 16:01:58.230: E/AndroidRuntime(9809):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
02-02 16:01:58.230: E/AndroidRuntime(9809):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
02-02 16:01:58.230: E/AndroidRuntime(9809):     at dalvik.system.NativeStart.main(Native Method)
02-02 16:01:58.230: E/AndroidRuntime(9809): Caused by: java.lang.NullPointerException
02-02 16:01:58.230: E/AndroidRuntime(9809):     at com.pearmak.drawing.ActivityA.onCreate(ActivityA.java:102)
02-02 16:01:58.230: E/AndroidRuntime(9809):     at android.app.Activity.performCreate(Activity.java:4470)
02-02 16:01:58.230: E/AndroidRuntime(9809):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
02-02 16:01:58.230: E/AndroidRuntime(9809):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
02-02 16:01:58.230: E/AndroidRuntime(9809):     ... 11 more
  • 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-18T04:18:26+00:00Added an answer on June 18, 2026 at 4:18 am

    you will need to pass Activity Context to Non Activity class by using constructor or by changing method to parametrized method as :

    public class PaintView extends View 
    {      
      Context context_new;
      public PaintView(Context context){
        this.context_new=context;
      }
       //.. your code here
       public void shareImage(Context context)
       {
    
         context.startActivity(Intent.createChooser(share, "Share drawing"));
         //OR
         //context_new.startActivity(Intent.createChooser(share, "Share drawing"));
          Toast.makeText(context, 
              "Please save the image first...",
                       Toast.LENGTH_LONG).show();   
    
          //OR
             // Toast.makeText(context_new, 
             // "Please save the image first...",
             //Toast.LENGTH_LONG).show(); 
    
       }
    
    }
    

    and call shareImage method from Activity as :

    PaintView paintview=new PaintView(Your_Current_Activity.this);
    paintview.shareImage(Your_Current_Activity.this);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making something like an augmented reality app, in which I have an OpenGL
I am making a drawing app for iOS and I have the following classes:
I have a question about making a drawing app for Android. What is the
I'm making a simple drawing app on Android. I'm using the FingerPaint.java provided with
I'm making a drawing app. In the centre of the screen, I want the
So I'm making a simple painting app for the Android SDK. However, the onTouchEvent()
I am making a simple app in which filled circles bounce around the screen.
I'm currently making an OpenGL ES 2.0 drawing app for the iPad and I
Hi i am making a sample app in which i wanto create a square
I am making a GUI program using gtkmm. I would like to draw some

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.