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

The Archive Base Latest Questions

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

I have the following thread: class LemonadeMainMenuThread extends Thread { private SurfaceHolder mSurfaceHolder; private

  • 0

I have the following thread:

class LemonadeMainMenuThread extends Thread {

    private SurfaceHolder mSurfaceHolder;
    private Handler mHandler;
    private Context mContext;
    int mRowId = 0;

    public void setRunning(boolean b) {
        mRun = b;
    }

    public LemonadeMainMenuThread(SurfaceHolder surfaceHolder,
            Context context, Handler handler) {
        mSurfaceHolder = surfaceHolder;
        mHandler = handler;
        mContext = context;
    }

    Resources res = getResources();

    @Override
    public void run() {
        while(1==1)
        {
        if (mRun) {
            try {
                c = mSurfaceHolder.lockCanvas(null);
                synchronized (mSurfaceHolder) {
                    doDraw(c);

                }
            } finally {
                if (c != null) {
                    mSurfaceHolder.unlockCanvasAndPost(c);
                }
            }

        }
        else{try { Thread.sleep(100); } catch (Exception ie) {}}
    }}

}

I also have the following methods in the same file:

public void surfaceCreated(SurfaceHolder arg0) {
    if (thread.getState() == Thread.State.TERMINATED) {
        thread = new LemonadeMainMenuThread(holder, ctx, new Handler() {
            @Override
            public void handleMessage(Message m) {
            }
        });
    }
    thread.setRunning(true);
    thread.start();
}
public LemonadeMainMenuThread setThreadRunning(boolean b) {
    mRun = b;
    if (thread.getState() == Thread.State.TERMINATED) {
        thread = new LemonadeMainMenuThread(holder, ctx, new Handler() {
            @Override
            public void handleMessage(Message m) {
            }
        });
    }
    return thread;
}

On my logic file, I have OnPause and OnResume events as follows:

@Override
protected void onPause() {
    mLemonadeMainMenuView.setThreadRunning(false);
    super.onPause();
}

@Override
protected void onResume() {
    mLemonadeMainMenuView.setThreadRunning(true);
    super.onResume();
    b=true;
}

The thread works fine normally, however when I exit the app and come back to it, it closes with the following errors:

FATAL EXCEPTION: Thread-13
03-27 
java.lang.NullPointerException
03-27
at com.example.HelloAndroid.LemonadeMainMenuView$LemonadeMainMenuThread.doDraw(LemonadeMainMenuView.java:106)

at com.example.HelloAndroid.LemonadeMainMenuView$LemonadeMainMenuThread.run(LemonadeMainMenuView.java:72)

Here is the DoDraw() method:

    private void doDraw(Canvas canvas) {
        canvas.drawColor(Color.BLACK);
        Paint p = new Paint();
        p.setColor(Color.RED);
        p.setStyle(Style.FILL);
        Paint p3 = new Paint();
        p3.setColor(Color.GREEN);
        p3.setStyle(Style.FILL);
        Paint p2 = new Paint();
        p2.setColor(Color.MAGENTA);
        p2.setStyle(Style.FILL);
        Paint paint = new Paint();
        paint.setColor(Color.TRANSPARENT);
        paint.setStyle(Style.FILL);

        canvas.drawBitmap(mFrog, mx, my, null);
        canvas.drawRect(0, height * 4 / 5, width, height, p);
        int fly=0;
        while(fly<5)
        {
        fly++;
        int xer=flyserd[(fly-1)*2];
        int yer=flyserd[((fly-1)*2)+1];
        canvas.drawCircle(xer, yer, 10, p3);
        }
        fly=0;
        if (clicked) {
            if (stages == 0) {
                stages = (int) (Math.sqrt(Math.pow(MouthX + mx + x + clickx
                        + x / 2, 2)
                        + Math.pow(MouthY + my + y + clicky + y / 2, 2))
                        * height / 40000);
                stages += 1;
            }

            if (systemtime + 10 < System.currentTimeMillis()) {
                systemtime = System.currentTimeMillis();
                if (stage < stages) {
                    stage++;
                    canvas.drawLine(MouthX + mx, MouthY + my,
                            ((clickx - (MouthX + mx)) * stage / stages)
                                    + MouthX + mx,
                            ((clicky - (MouthY + my)) * stage / stages)
                                    + MouthY + my, p2);
                    if (stage == stages) {
                        stage = 0;
                        stages = 0;
                        clicked = false;
                    }
                }
            }
        }
        b = false;
    }
  • 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:28:40+00:00Added an answer on June 1, 2026 at 12:28 am

    Follow the stack trace – it tells you the file, the class, the line number where the NPE occurred. Turn on line numbers in your IDE, find that line, and see which of the references you find is nul. Step through in a debugger. It should be easy to find – faster than asking here.

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

Sidebar

Related Questions

I have the following class public class MyClass { private int myAttr; public void
Inside a class of mine I have the following code: mHandler = createHandler(); private
I have the following piece of code: public class DumpLocationLog extends Thread { LocationManager
I have the following servlet: public class MyServlet extends HttpServlet { private static final
So I have the following code: import java.lang.Thread; import java.lang.Integer; class MyThread extends Thread
In a public static class I have the following local method: private static int
I have a DirectoryMonitor class which works on another thread. It has the following
Suppose I have the following thread: public class MyThread { public void run() {
I have following code: public class readSensorsData extends Activity implements SensorListener { /** Called
I have the following Interview question: class someClass { int sum=0; public void foo()

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.