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

  • Home
  • SEARCH
  • 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 7973913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:14:04+00:00 2026-06-04T08:14:04+00:00

While trying to calculate the function between a touch point (dx, dy), i am

  • 0

While trying to calculate the function between a touch point (dx, dy), i am receiving an error when calling the calculation function.

Here is my move function:

public class Mice {

public Movement getRatio;
public static float MX;
public static float MY;

public Mice(float x, float y){
    MX = x;
    MY = y;
}

public void move(float dx, float dy){
    float[] ratio = new float[2];
    //below this comment is my error:
    ratio = getRatio.getPath(dx, dy, MX, MY);
    MX++;
    MY = MY + ratio[1];
    GameActivity.mpx = MX;
    GameActivity.mpy = MY;
}

}

(MX, MY) is another point where an object is right now on the screen.

Here is my calculation function:

public class Movement {

public float[] getPath(float dx, float dy, float mX, float mY){
    float[] ratio = new float[2];
    ratio[0] = 1;
    float a;
    float Ry1;
    float Ry2;
    float Rx1 = 1;
    float Rx2 = 2;
    a = (dy-mY)/(dx-mX);
    Ry1=a*(Rx1-dx)+dy;
    Ry2=a*(Rx2-dx)+dy;
    ratio[1] = Math.abs(Ry1-Ry2);

    return ratio;
}

}

My onTouchEvent

@Override
public boolean onTouchEvent(MotionEvent event){

dx = event.getX();
dy = event.getY();


if(event.getAction()==1){
thread = new MiceThread(mice, mview, dx, dy);
thread.start();
}

return true;
}

And here is my thread:

public class MiceThread extends Thread {

private Mice gameMice;
private MiceView gameView;
private float x;
private float y;

public MiceThread(Mice theMice, MiceView theView, float x, float y){
    this.gameMice = theMice;
    this.gameView = theView;
    this.x = x;
    this.y = y;
}

public void run(){
    while(1<2){
        this.gameMice.move(x, y);
        this.gameView.postInvalidate();

        try
        {
            MiceThread.sleep(5);

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

    }
}

}

I am getting the error where specified in the first block of code.

Thanks!

  • 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-04T08:14:06+00:00Added an answer on June 4, 2026 at 8:14 am

    if you get a Null Pointer , I see you never initialized your Movement getRatio

    add it to your Constructor:

    public Mice(float x, float y){
    MX = x;
    MY = y;
    getRatio = new Movement();
    }
    

    and Fill in any parameter you need for your Movement…

    You Can also make a static Method inside your Movement like this:

    public class Movement {
    
        public static float[] getPath(float dx, float dy, float mX, float mY){
           ...
        }
    }
    

    and use it like this:

    public void move(float dx, float dy){
        float[] ratio = Movement.getPath(dx, dy, MX, MY);
        MX++;
        MY = MY + ratio[1];
        GameActivity.mpx = MX;
        GameActivity.mpy = MY;
    }
    

    your getPath(...) function has nothing to do with it.

    EDIT:

    Cannot Really help, because the lack of info. Only a few Notes…

    AVOID

    if(event.getAction()==1){
      thread = new MiceThread(mice, mview, dx, dy);
      thread.start();
    }
    

    Try it like

    if(event.getAction()==1){
        if (thread =! null){
            //kill Thread First. instead of while(1<2) add a boolean inside MiceThread.run 
            // and set it to false at this point.... 
            // if you don't this Thread may live as long as GC doesn't kill it.
        }
        thread = new MiceThread(mice, mview, dx, dy);
        thread.start();
    }
    

    Then

    public void run(){
    while(someBool){
        this.gameMice.move(x, y);
        //does your Mice View has a reference to this.gameMice???
        //if not update your Mice inside this.gameView....
        // I Cannot tell you how, because I don't know what MiceView is doing...
        //postInvalidate() works ONLY, if Something inside the VIEW had changed...
        this.gameView.postInvalidate();
    
        try
        {
            MiceThread.sleep(5);
    
        }
        catch (InterruptedException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While trying to host the CLR, I keep getting this: error C2440: 'function' :
While trying to execute the following lines only the last two statements are displayed(Here
While trying to GET a JSON, my callback function is NOT firing. $.ajax({ type:GET,
I'm trying to write some code to calculate a cumulative distribution function in matlab.
I'm trying to write a function that can calculate revenue at different tiered levels...
I'm trying to calculate the number of days between two days, but I'm running
I'm trying to write an elegant function in R to calculate the elapsed time
I'm trying to write a simple function in C that would calculate the difference
I'm trying to write a C function using OpenSSL/libcrypto to calculate the SHA256 sum
While trying to verify to myself, that C# Equals for IEnumerables is a reference

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.