gpt4 book ai didi

java - 无法启动 Activity ,行读取器中的 ArrayIndexOutOfBounds

转载 作者:太空宇宙 更新时间:2023-11-04 12:07:09 26 4
gpt4 key购买 nike

我不断收到ArrayIndexOutOfBoundsException,但我不确定代码的哪一部分到底导致了此错误。任何帮助将不胜感激。代码是

        while ((line = reader.readLine()) != null) {

String[] wordOnLine = line.split(",");
geo.put(wordOnLine[0] , new GeoLocation(wordOnLine[0], Double.parseDouble(wordOnLine[1]), Double.parseDouble(wordOnLine[2]),TimeZone.getTimeZone(wordOnLine[3])));

}

错误是

Unable to start activity ComponentInfo{swindroid.suntime/swindroid.suntime.ui.Main}: java.lang.ArrayIndexOutOfBoundsException: length=1; index=1

最佳答案

公共(public)列表 getListOfLocations() {

//  String fileName = "au_locations.txt";
// BufferedReader reader = null;
// StringBuilder builder = new StringBuilder();

InputStream input = getResources().openRawResource(R.raw.au_locations);
BufferedReader reader = new BufferedReader( new InputStreamReader((input)));
String line;
StringBuilder builder = new StringBuilder();
File file = new File(getFilesDir(), "au_locations.txt");

try {
// reader = new BufferedReader(new InputStreamReader(getAssets().open(fileName)));
// String line;

while ((line = reader.readLine()) != null) {
// builder.append(line).append("\n");
String[] wordOnLine = line.split(",");
geo.put(wordOnLine[0] , new GeoLocation(wordOnLine[0], Double.parseDouble(wordOnLine[1]), Double.parseDouble(wordOnLine[2]),TimeZone.getTimeZone(wordOnLine[3])));
//locations.add(line);
}

if(file.exists()){
FileInputStream inputFile = openFileInput("au_locations.txt");
input = inputFile;
reader = new BufferedReader((new InputStreamReader((input))));
while ((line = reader.readLine()) != null) {
// builder.append(line).append("\n");
String[] wordOnLine = line.split(",");
geo.put(wordOnLine[0] , new GeoLocation(wordOnLine[0], Double.parseDouble(wordOnLine[1]), Double.parseDouble(wordOnLine[2]),TimeZone.getTimeZone(wordOnLine[3])));

//locations.add(line);
}
}
// return locations;
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
reader.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}

关于java - 无法启动 Activity ,行读取器中的 ArrayIndexOutOfBounds,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40243268/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com