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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:57:41+00:00 2026-06-01T00:57:41+00:00

I am learning Android and java so this is probably an easy question. I

  • 0

I am learning Android and java so this is probably an easy question.

I am trying to call invalidate() on my DrawView. I have read up on it and I think the problem is that I cannot call invalidate outside of the UI thread (or something). As far as I know I only have one thread running as this is a simple TicTacToe game. so here is my code.

DrawView dv;

Create the dv object to associate it with the DrawView class

dv.invalidate();

trying to call the invalidate method.

This is the first part of my DrawView class

class DrawView extends View implements OnTouchListener, OnGestureListener
{
    public DrawView(Context context)
    {
        super(context);
        this.setOnTouchListener(this);

    }

    @Override
    protected void onDraw(Canvas canvas)
    {
                    canvas.drawColor(0xFF303030);
        Paint paint = new Paint();
        paint.setColor(0xFFFFFFFF);
        board.draw(canvas);
        detectEnd();
    }

it seems as if invalidate IS called however it crashes the program. Any ideas?

EDIT: I tried dv.postInvalidate()however it throws a null pointer exception. I have tried to initialize the DrawView dv in several ways but to no avail.

  • 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-01T00:57:43+00:00Added an answer on June 1, 2026 at 12:57 am

    If you are calling invalidate from outside the DrawView, you have to call postInvalidate() instead.

    Also, it generally isn’t ever a good idea to play sounds during the onDraw method.

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

Sidebar

Related Questions

So this is probably an easy thing that I'm trying to do but I'm
I'm learning android but have a pretty fair background in java so am a
I'm just starting out with learning Java, and have run into a problem. When
I'm learning android and java and am trying to learn how to make a
I am currently learning how to program Java in android. I read various artices
I'm still learning Android Development so sorry if this question seems stupid but I'm
this is my first post.. so I'm learning Android & Java (coming from Actionscript),
I started learning Java and how to program for Android last night :) So
I'm relatively new to Java, eclipse and android so this could be a completely
I have been slowing learning and building my first android app. I'm VERY new

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.