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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:08:21+00:00 2026-06-13T14:08:21+00:00

I have a problem with following simple code. I create GraphicView class which extends

  • 0

I have a problem with following simple code. I create GraphicView class which extends SurfaceView. I run it on another thread which starts at the onCreate method:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate( savedInstanceState );
    GraphicView v = new GraphicView( this );
    Thread thread = new Thread( v );
    thread.start();
    setContentView( v );    
}

I don’t know why but when I close my application – I get an error. I don’t use english UI on my tablet but I think on english it sound like this: “There was an error in the application”. And nothing more! Maybe I need to stop thread? Is there errors in my code?

public class GraphicView extends SurfaceView implements Runnable {

    Activity activity;
    SurfaceHolder holder;
    Paint paint;

    public GraphicView( Activity activity ) {

        super( activity );      

        this.activity = activity;

        paint = new Paint(); 
        paint.setColor( Color.YELLOW ); 
        paint.setStyle( Style.FILL ); 

        holder = getHolder();

    }

    @Override
    public boolean onTouchEvent( MotionEvent me ) {
        return false;
    }

    public void run() {

        while ( true ) {

            if ( !holder.getSurface().isValid() ) {
                continue;
            }

            Canvas c = holder.lockCanvas();
            c.drawARGB( 255, 128, 255, 80 );
            holder.unlockCanvasAndPost( c );

        }

    }

}

So the error is:

10-31 00:02:20.124: W/KeyCharacterMap(278): No keyboard for id 0
10-31 00:02:20.124: W/KeyCharacterMap(278): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
10-31 00:02:21.104: W/dalvikvm(278): threadid=11: thread exiting with uncaught exception (group=0x4001d800)
10-31 00:02:21.124: E/AndroidRuntime(278): FATAL EXCEPTION: Thread-10
10-31 00:02:21.124: E/AndroidRuntime(278): java.lang.NullPointerException
10-31 00:02:21.124: E/AndroidRuntime(278):  at com.example.GraphicView.run(GraphicView.java:192)
10-31 00:02:21.124: E/AndroidRuntime(278):  at java.lang.Thread.run(Thread.java:1096)

Line 192 of GraphicView.java:

c.drawARGB( 255, 128, 255, 80 );
  • 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-13T14:08:21+00:00Added an answer on June 13, 2026 at 2:08 pm

    Try replacing while(true) with while(!yourActivity.isFinishing())

    Perhaps even better you should break your loop in Activity’s onPause and resume it in onResume()

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

Sidebar

Related Questions

I have the following code, which implements a simple C++ class (ObjWithPyCallback) with a
I have quite an embarrassing problem. The following code simply will not create a
i have an problem with antlr. I have the following simple grammar: grammar bxk;
I have the following problem: I am creating a simple plugin jquery carousel, to
all! I have the following problem: I have 2 simple tables. The first one,
it is the problem, i can't undertand anyway. i have the following simple script
I have following problem, Code: String a=Yeahh, I have no a idea what's happening
I have a problem with following script. It generates a list of places which
I have used the following code to create the XML Document : procedure TForm1.btnCreateXMLClick(Sender:
I have the following issue whith this very simple task. I want to create

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.