在某些计算过程中获取StackOverflow异常

时间:2017-01-14 12:51:37

标签: java

我有以下代码(针对手榴弹轨迹的坐标计算)

public class GrenadeTrajectory
{
    public int speedValue;
    public static boolean shotStart;
    public boolean stop;
    ArrayList<Integer> xA = new ArrayList<Integer>();
    ArrayList<Integer> yA = new ArrayList<Integer>();
    Executor executor = Executors.newSingleThreadExecutor();
    Worms worms = new Worms();
    MapSettings MapSettings;
    public void startTask()
    {  
        stop = false;
        executor.execute(new Runnable() 
        {
            @Override
            public void run() 
            {
                int TRAJECTORY_STEPS = 10;
                double alpha = 45.0;
                double x0 = MapSettings.mp_player1_weapon_position_x;
                double y0 = MapSettings.mp_player1_weapon_position_y;
                double v0 = 50.0;
                double g = 8.91;
                double c = Math.sqrt(Math.pow((worms.getWeaponDirectionPosition(true) + MapSettings.mp_player1_weapon_position_x), 2));
                double degrees = Math.acos((worms.getWeaponDirectionPosition(true) - MapSettings.mp_player1_weapon_position_x) / Math.pow(worms.getWeaponDirectionPosition(true) - MapSettings.mp_player1_starting_position_x, 2) - Math.pow(MapSettings.mp_player1_starting_position_y - worms.getWeaponDirectionPosition(false), 2));
                double[] arrayX = new double[TRAJECTORY_STEPS];
                double[] arrayY = new double[TRAJECTORY_STEPS];
                for (int t = 0; t < TRAJECTORY_STEPS; t++)
                {

                    arrayX[t] = x0+v0*Math.cos(degrees)*t;
                    arrayY[t] = y0+v0*Math.sin(degrees)*t-0.5*g*t*t;
                    System.out.format("t=%d x=%f y=%f", t, arrayX[t], arrayY[t]);
                }
                Thread.currentThread().stop();  
            }  
        });
    }
    public void setCons(Worms w, MapSettings cfg)
    {
        xA.clear();
        yA.clear();
        worms = w;
    }
    public void stopTask() throws InterruptedException
    {     
        stop = true; 
    }  
}

我收到了以下错误/例外情况:

Exception in thread "main" java.lang.StackOverflowError
    at java.util.concurrent.AbstractExecutorService.<init>(AbstractExecutorService.java:71)
    at java.util.concurrent.ThreadPoolExecutor.<init>(ThreadPoolExecutor.java:1305)
    at java.util.concurrent.ThreadPoolExecutor.<init>(ThreadPoolExecutor.java:1198)
    at java.util.concurrent.Executors.newSingleThreadExecutor(Executors.java:134)
    at com.worms.ShotPower.<init>(ShotPower.java:15)
    at com.worms.Worms.<init>(Worms.java:31)
    at com.worms.GrenadeTrajectory.<init>(GrenadeTrajectory.java:19)

那些例外我在那里有1000次。错误在线

 double c = Math.sqrt(Math.pow((worms.getWeaponDirectionPosition(true) + MapSettings.mp_player1_weapon_position_x), 2));

我做错了什么,如何解决这个问题?感谢。

0 个答案:

没有答案