简体   繁体   English

线程“main”中的异常 java.lang.ArrayIndexOutOfBoundsException: 1 at hibiserver2.connect.FinalAuthetication(connect.java:68)

[英]Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1 at hibiserver2.connect.FinalAuthetication(connect.java:68)

Hi Im new to java and eclipse.嗨,我是 Java 和 Eclipse 的新手。 I am ordered to make the old project code to run again.我被命令让旧的项目代码再次运行。 Hope you guys can help me please.希望你们能帮助我。 I get this error:我收到此错误:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1 at hibiserver2.connect.FinalAuthetication(connect.java:68) at hibiserver2.main.main(main.java:10)线程“main”中的异常 java.lang.ArrayIndexOutOfBoundsException: 1 at hibiserver2.connect.FinalAuthetication(connect.java:68) at hibiserver2.main.main(main.java:10)

Line 68 is:第 68 行是:

String[] bbbb = bbb[1].split("\\)"); 

in connect.java在connect.java

Here is my connect.java这是我的connect.java

package hibiserver2;

import java.math.BigInteger;
import java.security.SecureRandom;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;

import jssc.SerialPort;
import jssc.SerialPortException;

public class connect {
    private Connection con;
    private java.sql.Statement st;
    private ResultSet rs;
    Curve curve;
    SecureRandom rand;
    CpxBigInteger G1,G2,GT;
    BigInteger order,r;
    SerialPort serialPort = new SerialPort("COM9");
    private static String sql;
    {
    curve = new Curve(160, 512);
    order = curve.getorder();
    //g0 = curve.getTorsionPoint();
    rand=new SecureRandom();
    }
    //Connection for Database
    public connect(){
        try{
            Class.forName("com.mysql.jdbc.Driver");

            con =DriverManager.getConnection("jdbc:mysql://localhost:3306/hibi","root","");
            st = con.createStatement();


        }catch(Exception ex){
            System.out.println("Error: " + ex);
        }
                }

    public String FinalAuthetication(){

        ComPortConnectionOpen();

        //getdata
        //String gg = getDataG0();
        String gg = "(1505849116485661454412997865679475610553835166796270819501271602139967042497844079916919792062803853583367321606338605429742000822208605304206964160747311,5130223886975130167986114874933598639380987886566526095885374086984146604883828811891365376209108870956965991533299556155493014336762647662924972622515035)";
        String zz = getDataZ();
        //String qq = getDataQ();
        String qq = "(1585555122124020330681559123403410531843372898179271040837672453884103408853079031676952531181098567768697094644697545868098257589265897895223756473851765,6055810885359522509776528877610343750172396344322567832074954246459492702478212226632300470957497266699734949257588603748017102542818535621527980919482311)";
        String xx = getDataX();
        String gg1 = getDataG1();
        String cc = getDataC();
        String ss = getDataS0();
        //String rr = getDataR();

        //convert string gg to point
         String[] ddd = gg.split("\\(");
         String[] dddd = ddd[1].split("\\)");
         String[] dd = dddd[0].split(",");
         BigInteger dd1 = new BigInteger (dd[0]);
         BigInteger dd2 = new BigInteger (dd[1]);
         Point g0 = new Point(curve, dd1,false, dd2, false);

        //convert string zz to point
         String[] bbb = zz.split("\\(");
         String[] bbbb = bbb[1].split("\\)");
         String[] bb = bbbb[0].split(",");
         BigInteger bb1 = new BigInteger (bb[0]);
         BigInteger bb2 = new BigInteger (bb[1]);
         Point Z = new Point(curve, bb1,false, bb2, false);

        //convert string qq to point
         String[] aaa = qq.split("\\(");
         String[] aaaa = aaa[1].split("\\)");
         String[] aa = aaaa[0].split(",");
         BigInteger aa1 = new BigInteger (aa[0]);
         BigInteger aa2 = new BigInteger (aa[1]);
         Point q0 = new Point(curve, aa1,false, aa2, false);


        //convert string xx to point
         String[] eee = xx.split("\\(");
         String[] eeee = eee[1].split("\\)");
         String[] ee = eeee[0].split(",");
         BigInteger ee1 = new BigInteger (ee[0]);
         BigInteger ee2 = new BigInteger (ee[1]);
         Point x1 = new Point(curve, ee1,false, ee2, false);

        //convert string gg1 to point
         String[] www = gg1.split("\\(");
         String[] wwww = www[1].split("\\)");
         String[] ww = wwww[0].split(",");
         BigInteger ww1 = new BigInteger (ww[0]);
         BigInteger ww2 = new BigInteger (ww[1]);
         Point g1 = new Point(curve, ww1,false, ww2, false);

         //convert string ss to biginteger
         //BigInteger s0 = new BigInteger(ss);

         //convert rr to biginteger
         //BigInteger r = new BigInteger(rr);


         //convert string c to biginteger
         BigInteger c = new BigInteger(cc);

         CpxBigInteger before =  curve.tatepairing(g0, Z); 

         G1= curve.tatepairing(q0,x1.Add(g1.Multiply(c)));
        // G2 = curve.tatepairing(q1,x2.Add(g2.Multiply(c)));
        // GT = G1.multiply(G2);

          if(before.equals(G1))

          {
            ComPortConnectionWrite();  
            return "Authentication PASS";
          }
          else{
              return "Authentication FAIL";
          }

    }

    public void ComPortConnectionOpen(){

      try {
          serialPort.openPort();//Open serial port
          serialPort.setParams(SerialPort.BAUDRATE_9600, 
                               SerialPort.DATABITS_8,
                               SerialPort.STOPBITS_1,
                               SerialPort.PARITY_NONE);//Set params. Also you can set params by this string: serialPort.setParams(9600, 8, 1, 0);

      }
      catch (SerialPortException ex) {
          System.out.println(ex);
            }
    }

    public void ComPortConnectionWrite(){
        try{
          serialPort.writeBytes("e".getBytes());//Write data to port
          serialPort.closePort();//Close serial port
        }
        catch (SerialPortException ex){
            System.out.println(ex);
            }


    }

}

And here is my main.java这是我的 main.java

public class main {



    public static void main(String[] args) {
            // TODO Auto-generated method stub
            connect connect =new connect();
            //System.out.println("hello");
            String result = connect.FinalAuthetication();
            System.out.println(result);

    }

}

Anyone can tell me whats the problem please.任何人都可以告诉我什么问题。 Im thanks in advance for those who willing to help.我提前感谢那些愿意提供帮助的人。

Seeing your code, let me give you some insight to your problem:看到你的代码,让我给你一些洞察你的问题:

String[] bbb = zz.split("\\(");
String[] bbbb = bbb[1].split("\\)");

As your error said: you have an Array Index Out of bounds exception at:正如您的错误所说:您在以下位置有一个数组索引越界异常:

String[] bbbb = bbb[1].split("\\)"); 

Looking at your code;查看您的代码; bbb is an array of strings that you obtained by splitting zz . bbb是您通过拆分zz获得的字符串数组。 From the error you get it is obvious that the result of zz.split("\\\\("); returns an array with less than two elements meaning that the regex/delimiter \\\\( was not contained in the string zz .从您得到的错误中可以明显看出zz.split("\\\\(");返回一个少于两个元素的数组,这意味着正则表达式/分隔符\\\\(不包含在字符串zz

So trying to access bbb[1] which is the second item in your array bbb (which doesn't exist) will throw an Array Index Out Of bounds Exception.因此,尝试访问bbb[1]是数组bbb的第二项(不存在)将引发数组索引越界异常。

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

相关问题 线程“main”中的异常 java.lang.ArrayIndexOutOfBoundsException: 7 - Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7 线程“主”中的异常java.lang.ArrayIndexOutOfBoundsException:6 - Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 6 线程“main”中的异常java.lang.ArrayIndexOutOfBoundsException:2 - Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException:2 线程“主”中的异常java.lang.ArrayIndexOutOfBoundsException:5 - Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 5 线程“主”中的异常java.lang.ArrayIndexOutOfBoundsException: - Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 线程“主”中的异常java.lang.ArrayIndexOutOfBoundsException:-1 - Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: -1 线程“ main”中的异常java.lang.ArrayIndexOutOfBoundsException 4 - Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException 4 线程“main”中的异常 java.lang.ArrayIndexOutOfBoundsException - Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException 线程“ main”中的异常java.lang.ArrayIndexOutOfBoundsException:3 - Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 3 线程“ main”中的异常java.lang.ArrayIndexOutOfBoundsException:8 - Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 8
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM