线程 "main" java.lang.ArrayIndexOutOfBoundsException 中的异常:1 在 hibiserver2.connect.FinalAuthetication(connect.java:68)
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1 at hibiserver2.connect.FinalAuthetication(connect.java:68)
嗨,我是 java 和 eclipse 的新手。我奉命将旧项目代码重新设为运行。希望你们能帮助我。
我收到此错误:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at hibiserver2.connect.FinalAuthetication(connect.java:68) at
hibiserver2.main.main(main.java:10)
第 68 行是:
String[] bbbb = bbb[1].split("\)");
在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);
}
}
}
这是我的 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);
}
}
任何人都可以告诉我有什么问题。在此先感谢那些愿意提供帮助的人。
看到你的代码,让我给你一些关于你的问题的见解:
String[] bbb = zz.split("\(");
String[] bbbb = bbb[1].split("\)");
如您的错误所述:您在以下位置遇到数组索引越界异常:
String[] bbbb = bbb[1].split("\)");
正在查看您的代码; bbb
是拆分zz
得到的字符串数组。从错误中可以明显看出 zz.split("\(");
returns 的结果是一个少于两个元素的数组,这意味着 regex/delimiter \(
不包含在字符串 zz
.
因此尝试访问数组 bbb
中的第二项 bbb[1]
(不存在)将抛出数组索引越界异常。
嗨,我是 java 和 eclipse 的新手。我奉命将旧项目代码重新设为运行。希望你们能帮助我。 我收到此错误:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1 at hibiserver2.connect.FinalAuthetication(connect.java:68) at hibiserver2.main.main(main.java:10)
第 68 行是:
String[] bbbb = bbb[1].split("\)");
在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);
}
}
}
这是我的 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);
}
}
任何人都可以告诉我有什么问题。在此先感谢那些愿意提供帮助的人。
看到你的代码,让我给你一些关于你的问题的见解:
String[] bbb = zz.split("\(");
String[] bbbb = bbb[1].split("\)");
如您的错误所述:您在以下位置遇到数组索引越界异常:
String[] bbbb = bbb[1].split("\)");
正在查看您的代码; bbb
是拆分zz
得到的字符串数组。从错误中可以明显看出 zz.split("\(");
returns 的结果是一个少于两个元素的数组,这意味着 regex/delimiter \(
不包含在字符串 zz
.
因此尝试访问数组 bbb
中的第二项 bbb[1]
(不存在)将抛出数组索引越界异常。