在我的手机昨晚更新之前,我的代码运行良好。我正在使用 opencsv 将手机存储中的 CSV 文件读取到我的应用程序中的数组中。这是代码...
public static String[] getFileContents(File file) {
String[] contentsArray = new String[500];
if(file.exists()) {
try {
CSVReader reader = new CSVReader(new FileReader(file));
String[] nextLine;
while ((nextLine = reader.readNext()) != null) {
System.arraycopy(nextLine, 0, contentsArray, 0, nextLine.length);
}
} catch (Exception e) {
System.out.println("Failed file: " + file);
System.out.println("You are here and sad but at least the file exists");
e.printStackTrace();
}
} else {
System.out.println("File does not exist");
}
return contentsArray;
}
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误...
I/System.out: Failed file: /storage/emulated/0/Documents/text/36-12644-Test …Run Code Online (Sandbox Code Playgroud) 我想通过for循环填充一些TextViews.这不是一个真正的代码示例,但我希望它足以让您了解我正在尝试做什么.我甚至不确定这是可能的,但我希望有人找到了办法.
TextView dataTV0 = (TextView) v.findViewById(R.id.dataTV0);
TextView dataTV1 = (TextView) v.findViewById(R.id.dataTV1);
TextView dataTV2 = (TextView) v.findViewById(R.id.dataTV2);
TextView dataTV3 = (TextView) v.findViewById(R.id.dataTV3);
TextView dataTV4 = (TextView) v.findViewById(R.id.dataTV4);
TextView dataTV5 = (TextView) v.findViewById(R.id.dataTV5);
String[] data; //This is acquired from another source
for (int i = 0; i < 6; i++){
(String.format("dataTV%d", i).setText(data[i]);
}
Run Code Online (Sandbox Code Playgroud)