-2
我的Java代碼有問題。我試圖找出錯誤是什麼問題。也許你可以幫助我。ArrayIndexOutOfBoundsException請幫助我
public static void Convert1() throws IOException,ArrayIndexOutOfBoundsException,NumberFormatException {
String csv ="/Users/Max/IdeaProjects/Download/Asset1.csv";
BufferedReader br = null;
String line = "";
String csvSplitBy = ";";
File file = new File ("/Users/Max/IdeaProjects/Download/Datum1.csv");
if (file.exists()) {
} else {
br = new BufferedReader(new FileReader(csv));
while ((line = br.readLine()) != null) {
String[] asset = line.split(csvSplitBy);
String[] Date = {asset[0]}; //Datum
String[] Open = {asset[1]}; //Öffnungskurs
String[] High = {asset[2]}; //Tageshoch
String[] Low = {asset[3]}; //Tagestief
String[] Close = {asset[4]}; //Schlusskurs
String[] Volume = {asset[5]}; //Handelsvolumen
// Es werden die Dateien geschrieben die die einzelnen Teilbereiche enthalten
BufferedWriter BW = new BufferedWriter(new FileWriter("Datum1.csv", true));
StringBuilder SB = new StringBuilder();
for (String element : Date) {
SB.append(element);
SB.append(";");
}
BW.write(SB.toString());
BW.close();
BufferedWriter BW2 = new BufferedWriter(new FileWriter("Öffnungskurs1.csv", true));
StringBuilder SB2 = new StringBuilder();
for (String element : Open) {
SB2.append(element);
SB2.append(";");
}
BW2.write(SB2.toString());
BW2.close();
BufferedWriter BW3 = new BufferedWriter(new FileWriter("Tageshoch1.csv", true));
StringBuilder SB3 = new StringBuilder();
for (String element : High) {
SB3.append(element);
SB3.append(";");
}
BW3.write(SB3.toString());
BW3.close();
BufferedWriter BW4 = new BufferedWriter(new FileWriter("Tagestief1.csv", true));
StringBuilder SB4 = new StringBuilder();
for (String element : Low) {
SB4.append(element);
SB4.append(";");
}
BW4.write(SB4.toString());
BW4.close();
BufferedWriter BW5 = new BufferedWriter(new FileWriter("Schlusskurs1.csv", true));
StringBuilder SB5 = new StringBuilder();
for (String element : Close) {
SB5.append(element);
SB5.append(";");
}
BW5.write(SB5.toString());
BW5.close();
BufferedWriter BW6 = new BufferedWriter(new FileWriter("Handelsvolumen1.csv", true));
StringBuilder SB6 = new StringBuilder();
for (String element : Volume) {
SB6.append(element);
SB6.append(";");
}
BW6.write(SB6.toString());
BW6.close();
}
}
}
每次我想運行我得到以下異常。
異常線程 「main」 java.lang.ArrayIndexOutOfBoundsException:1 在ConvertCSVtoArraysAsset1.Convert1(ConvertCSVtoArraysAsset1.java:30)
也許你可以幫我這一點。
問候
正如你可以看到,我們沒有行號在這裏。也許你可以告訴我們第30行。 – tnw