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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:31:21+00:00 2026-06-04T04:31:21+00:00

I’m making a drawing app, and randomly when I press down, the app crashes.

  • 0

I’m making a drawing app, and randomly when I press down, the app crashes. I can’t figure out how to fix it, and have no Idea where to start. I don’t know whether it is the List or the timing, or something else. Here’s my code:

package com.orangewhales.paint.views;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Paint.Style;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;

public class PaintView extends SurfaceView implements Callback {

boolean run = true;
Thread tUpdate;
public List<PaintPath> paths = new ArrayList<PaintPath>();

public Paint stroke = new Paint();

@Override
public void draw(Canvas canvas) {
    // TODO Auto-generated method stub
    super.draw(canvas);

    canvas.drawRGB(255, 255, 255);

    for (PaintPath path : paths) {
        canvas.drawPath(path.path, path.paint);
    }
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    // TODO Auto-generated method stub
    switch(event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        Path current = new Path();
        current.moveTo(event.getX(), event.getY());
        paths.add(new PaintPath(current, stroke));
        break;

    case MotionEvent.ACTION_MOVE:
        PaintPath path = paths.get(paths.size() - 1);
        path.path.lineTo(event.getX(), event.getY());
        break;
    }


    return true;
}

public PaintView(Context context, AttributeSet attrs) {
    super(context, attrs);

    stroke.setStyle(Style.STROKE);
    stroke.setColor(Color.BLACK);
    stroke.setStrokeWidth(10);

    tUpdate = new Thread() {

        public void run() {
            while (run) {
                Canvas c = getHolder().lockCanvas();
                draw(c);
                getHolder().unlockCanvasAndPost(c);

                update();

                try {
                    sleep(10);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }

    };

    getHolder().addCallback(this);
}

public void update() {
    // TODO Auto-generated method stub

}

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
        int height) {
    // TODO Auto-generated method stub

}

@Override
public void surfaceCreated(SurfaceHolder holder) {
    // TODO Auto-generated method stub
    tUpdate.start();
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
    // TODO Auto-generated method stub
    run = false;

    try {
        tUpdate.join();
    } catch (InterruptedException 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-04T04:31:22+00:00Added an answer on June 4, 2026 at 4:31 am

    I have not touched my Android SDK in a while. So I’ll start with a question.

    You said the app crashes at random times when the GUI is pressed down. At function onTouchEvent, which action occurs first, ACTION_DOWN or ACTION_MOVE?
    I hope it’s well defined but we can not assume that.

    I find code in the function “PaintPath path = paths.get(paths.size() – 1)” to be suspicious because paths.size can be 0, in the beginning anyway.

    I think it’s a good idea to monitor the function onTouchEvent closely, can use debugger. Log messages if you have nothing else.

    Fixing random intermittent issues is part of the job. Learn from it and have fun.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
Specifically, suppose I start with the string string =hello \'i am \' me And
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build

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.