简体   繁体   English

“主”线程中的JavaScript到Java异常java.lang.NumberFormatException:对于输入字符串:“”

[英]JavaScript To Java Exception in thread “main” java.lang.NumberFormatException: For input string: “”

Hi am trying to convert my JavaScript decrypt method to Java can't seem to be able to do it since am stuck here i am inputting the string i don't why its saying am not ... 嗨,我试图将我的JavaScript解密方法转换为Java似乎无法做到这一点,因为我被卡在这里,我正在输入字符串,我不明白为什么它的意思不是...

Error Code: 错误代码:

Exception in thread "main" java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Integer.parseInt(Integer.java:592)
    at ae.df.sux.Main.Decrypt1(Main.java:42)
    at ae.df.sux.Main.main(Main.java:7)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

Java Code: Java代码:

public static String Decrypt1(String strIn) {
    String strOut = "";
    int lenIn = strIn.length();
    int i = 0;

    int A;
    int B;

    while (i < lenIn) {
        A = Integer.parseInt(strIn.substring(i, 2), 27);
        B = Integer.parseInt(strIn.substring(i + 2, 2), 27);
        strOut+= fromCharCode(A - B);
        i+=4;
    }
    return strOut;
}

JavaScript: JavaScript的:

Decrypt1 = function (strIn) {
    var strOut = String();
    var lenIn = strIn.length;
    var i = 0;
    var numA;
    var numB;
    while (i < lenIn) {
        numA = parseInt(strIn.substr(i, 2), 27);
        numB = parseInt(strIn.substr(i + 2, 2), 27);
        strOut += String.fromCharCode(numA - numB);
        i += 4;
    }
    return strOut;
};

The java error line: Java错误行:

B = Integer.parseInt(strIn.substring(i + 2, 2), 27);

So the value is encrypted: 因此该值是加密的:

431o5m215e1e723d7o3h6f2j401j4j2d7b345k1c631o59267j3g6627531a7a385o3g5125582g592n4l1l66395d2d4b1l4i1p531m4a1f5k2g4p2e4o205h2j693j3l1f593g7d3679317832511p5i1f6l2m6i2p7f3d58305f397g3j5c1a712k4e21783c5m267d374g1o5p3b4b234p314h2l4q2n52325e3i391b44215a3d5a344q36793c74325i1a411f6h2l5i226o2i4o254e205k3c552q391g682e7b3b5h216l2e6k2o3j1b

It should return: 它应该返回:

<flash><strToken>MICQNQGJYLUANOG</strToken><intCharID>32962493</intCharID></flash>

I don't know what the problem is thanks for the help. 我不知道问题出在哪里,谢谢您的帮助。

Not all Java functions behave exactly as same as other javascript functions. 并非所有Java函数的行为都与其他JavaScript函数完全相同。 You have to check what the function returns. 您必须检查该函数返回什么。 I have modified your java code to get desired output. 我已经修改了您的Java代码以获得所需的输出。

 public static String Decrypt1(String strIn) {
    String strOut = "";
    int lenIn = strIn.length();
    int i = 0;

    int A;
    int B;
    int nextIndex = 0;
    while (i < lenIn) {
        nextIndex = i+4;
        String aStr= strIn.substring(i, i+2);
        String bStr= strIn.substring(i + 2, nextIndex);

        System.out.println("astr:"+aStr);
        System.out.println("bstr:"+bStr);
        A = Integer.parseInt(aStr, 27);
        B = Integer.parseInt(bStr, 27);

        System.out.println("A:"+A);
        System.out.println("B:"+B);

        int C = A- B;
        System.out.println("C:"+C);

        String charStr = new String(Character.toChars(C));

        System.out.println("charStr :" +charStr);


        strOut+= charStr;
        i+=4;
    }

    System.out.println("output:"+strOut);
    return strOut;
}

 output:<flash><strToken>MICQNQGJYLUANOG</strToken><intCharID>32962493</intCharID></flash>

暂无
暂无

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

相关问题 java.lang.NumberFormatException:对于输入字符串:“ + i +” - java.lang.NumberFormatException: For input string: “+i+” 弹出jsp java.lang.NumberFormatException:null - pop-up jsp java.lang.NumberFormatException: null 错误:异常的构建过程终止:线程“ main”中的异常java.lang.NoSuchMethodError: - Error:Abnormal build process termination: Exception in thread “main” java.lang.NoSuchMethodError: 从Nashron JavaScript运行Java-异常java.lang.ClassNotFoundException - Running Java from Nashron JavaScript - Exception java.lang.ClassNotFoundException 线程“主”java.util.UnknownFormatConversionException 中的异常:转换 = '*' - Exception in thread “main” java.util.UnknownFormatConversionException: Conversion = '*' Rhino将java.lang.String转换为JavaScript String - Rhino conversion java.lang.String to JavaScript String 异常:java.lang.NullPointerException - Exception: java.lang.NullPointerException Selenium、java、js“线程“主”org.openqa.selenium.JavascriptException 中的异常:在参数列表后丢失) - Selenium, java, js "Exception in thread "main" org.openqa.selenium.JavascriptException: missing ) after argument list" 无法将类型“java.lang.String”的值转换为所需的类型“long”; 对于输入字符串:“{id}” - Failed to convert value of type 'java.lang.String' to required type 'long'; For input string: "{id}" 在JavaScript中创建输入隐藏类型Element数组,并在Servlet中获取值,但java.lang.NullPointerException - Create input hidden type Element array in JavaScript and get values in Servlet but java.lang.NullPointerException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM