简体   繁体   English

Java代码在android上给出了不同的结果

[英]Java Code gives different results on android

I have some code, running on the PC as just java code, it gives the answer I want (the right one). 我有一些代码,在PC上运行只是java代码,它给出了我想要的答案(正确的)。 On android the same code gives very different answers. 在Android上,相同的代码给出了非常不同的答案。

The code I am using was originally from the JsatTrack project, and gives these answers jun as a java project in eclipse (correct answers): 我使用的代码最初来自JsatTrack项目,并将这些答案作为eclipse中的java项目提供(正确答案):

Lat [deg]:10.386382587628313
Lon [deg]:-93.88496253189982
Alt [m]  :418288.8335920386

The same code, with same input on Android gives this result: 在Android上使用相同输入的相同代码会给出以下结果:

Lat [deg]:-37.97635062163793
Lon [deg]:-147.34940989563563
Alt [m]  :6.86973250782099E29

I am new to java so where would I start looking to track down a problem like this. 我是java的新手,所以我会在哪里开始寻找这样的问题。 Would it be in the way android handles math for example? 它会以android处理数学的方式吗?

So I guess my question boils down to why would the PC and android give different answers to the same maths questions? 所以我想我的问题归结为为什么PC和android会给出相同数学问题的不同答案? 2+2 should give t he same answer on any platform. 2 + 2应该在任何平台上给出相同的答案。 The math in the SGP4 models is more complex but it's still just math. SGP4模型中的数学运算更复杂,但它仍然只是数学。

The code is available here if any one wants to have a look 如果有人想看看,这里的代码可用

https://dl.dropbox.com/u/70291490/jstest.zip https://dl.dropbox.com/u/70291490/jstest.zip

I am new to java so where would I start looking to track down a problem like this?

Connect your Android phone via USB on the PC and on Eclipse double click the left-hand side of the relative code that starts doing the math, it should appear a blue dot (code breakpoint). 在PC上通过USB连接Android手机,在Eclipse上双击开始进行数学运算的相关代码的左侧,它应该显示一个蓝点(代码断点)。 Click the button with a little bug on it (DEBUG button) on Eclipse toolbar. 单击Eclipse工具栏上带有一点错误的按钮(DEBUG按钮)。 It will launch the project on the device and stop processing wherever u put the dot. 它将在设备上启动项目,并在您放置点的任何地方停止处理。

Now you can use the debug view toolbar to go through the code line-by-line and hoover the mouse on your classes/fields to see their values. 现在,您可以使用调试视图工具栏逐行浏览代码,并将鼠标悬停在类/字段上以查看其值。 You can do the same on the PC and compare each other value. 您可以在PC上执行相同操作并比较其他值。

The problem was very similar to my previous question on stackoverflow (http://stackoverflow.com/questions/14190692/how-to-debug-dalvikvm-rejecting-opcode) 问题与我之前关于stackoverflow的问题非常相似(http://stackoverflow.com/questions/14190692/how-to-debug-dalvikvm-rejecting-opcode)

Android can't handle lots of local variables, so defining them outside of the method is the solution. Android无法处理大量局部变量,因此在方法之外定义它们就是解决方案。 In my previous question dalvikvm was rejecting the method. 在我之前的问题中,dalvikvm拒绝了这种方法。 In this case it was different, this code here: 在这种情况下它是不同的,这里的代码如下:

ss = 78.0 / radiusearthkm + 1.0;

was setting ss as 1.0 as while radiuseathkm was being set a few lines earlier in the debugger it has a value of 0.0 when it should be 6378.135 so ss would = 1.0122292801892716. 将ss设置为1.0,因为在调试器中,如果将radiuseathkm设置为几行,则它应该为6378.135时值为0.0,因此ss将= 1.0122292801892716。 That error then propagates through the next few hundred calculations and there is the problem. 然后,该错误会在接下来的几百次计算中传播,并且存在问题。

So I changed this: 所以我改变了这个:

public static boolean sgp4init(
        Gravconsttype whichconst, char opsmode, final int satn, final double epoch,
        final double xbstar, final double xecco, final double xargpo,
        final double xinclo, final double xmo, final double xno,
        final double xnodeo, SGP4SatData satrec)
{
    /* --------------------- local variables ------------------------ */
    double ao, ainv, con42, cosio, sinio, cosio2, eccsq,
            omeosq, posq, rp, rteosq,
            cnodm, snodm, cosim, sinim, cosomm, sinomm, cc1sq,
            cc2, cc3, coef, coef1, cosio4, day, dndt,
            em, emsq, eeta, etasq, gam, argpm, nodem,
            inclm, mm, nm, perige, pinvsq, psisq, qzms24,
            rtemsq, s1, s2, s3, s4, s5, s6,
            s7, sfour, ss1, ss2, ss3, ss4, ss5,
            ss6, ss7, sz1, sz2, sz3, sz11, sz12,
            sz13, sz21, sz22, sz23, sz31, sz32, sz33,
            tc, temp, temp1, temp2, temp3, tsi, xpidot,
            xhdot1, z1, z2, z3, z11, z12, z13,
            z21, z22, z23, z31, z32, z33,
            qzms2t, ss, j2, j3oj2, j4, x2o3, //r[3], v[3],
            tumin, mu, radiusearthkm, xke, j3;
    double[] r = new double[3];
    double[] v = new double[3];

to this: 对此:

static double radiusearthkm, ao, ainv, con42, cosio, sinio, cosio2, eccsq,
        omeosq, posq, rp, rteosq,
        cnodm, snodm, cosim, sinim, cosomm, sinomm, cc1sq,
        cc2, cc3, coef, coef1, cosio4, day, dndt,
        em, emsq, eeta, etasq, gam, argpm, nodem,
        inclm, mm, nm, perige, pinvsq, psisq, qzms24,
        rtemsq, s1, s2, s3, s4, s5, s6,
        s7, sfour, ss1, ss2, ss3, ss4, ss5,
        ss6, ss7, sz1, sz2, sz3, sz11, sz12,
        sz13, sz21, sz22, sz23, sz31, sz32, sz33,
        tc, temp, temp1, temp2, temp3, tsi, xpidot,
        xhdot1, z1, z2, z3, z11, z12, z13,
        z21, z22, z23, z31, z32, z33,
        qzms2t, ss, j2, j3oj2, j4, x2o3, //r[3], v[3],
        tumin, mu,  xke, j3;


public static boolean sgp4init(
        SGP4unit_a.Gravconsttype whichconst, char opsmode, final int satn, final double epoch,
        final double xbstar, final double xecco, final double xargpo,
        final double xinclo, final double xmo, final double xno,
        final double xnodeo, SGP4SatData satrec)
{

    double[] r = new double[3];
    double[] v = new double[3];

and all is now working correctly. 现在一切都正常了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用JAVA和Python编写的相同代码给出不同的结果(粒子过滤器) - Same code written in JAVA and Python gives different results (particle filter) 使用RSA / ECB / PKCS1padding的Android加密问题。 它在Java和Android中给出不同的结果 - Issue in Android Encryption using RSA/ECB/PKCS1padding. It gives different results in Java and Android Java显式类型转换给出不同的结果 - java explicit type conversion gives different results 用Java重写的Javascript函数给出不同的结果 - Javascript function rewritten in Java gives different results Java-关闭套接字会产生不同的结果 - Java - closing socket gives different results 用Java和Excel进行批处理可获得不同的结果 - Batching in Java and Excel gives different results RSA公钥编码,在Java和Android中,代码相同,结果不同 - RSA public key encode, in Java and Android, same code, different results 在命令行中从Java代码运行grep命令会得到不同的结果 - running grep command in command line and from java code gives different results Tesseract没有给出任何识别结果(Android studio; Java) - Tesseract gives no recognition results (Android studio; Java) Lucene中文分析器Jcseg使用相同的代码将得出不同的结果 - Lucene Chinese Analyzer Jcseg Using same code gives different results
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM