I've got a problem with OpenCSV lib; precisely, with writing Strings into the file itself.
public class Calc {
public static Summary summary;
public static CSVWriter writer;
(...)
someButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
(...)
summary = new Summary();
writer = summary.createCSV();
someThreadedMethod();
summary.closeWriter(writer);
} catch (...) {}
}
}
}
}
Summary class:
public class Summary {
private static int version = 0;
private static String name;
public Summary() throws IOException {
this.version += 1;
this.name = "Summary" + Integer.toString(version) + ".csv";
}
public CSVWriter createCSV() throws IOException {
CSVWriter writer = new CSVWriter(new FileWriter(name));
return writer;
}
public void addInfo(CSVWriter writer, String info) {
String[] record = info.split("#");
writer.writeNext(record);
}
public void closeWriter(CSVWriter writer) throws IOException {
writer.close();
}
}
And someThreadedMethod() creates another classes objects which log into given website and parse given Strings form tables:
(...)
ArrayList<String> contentStrToPrint = new ArrayList<>(Arrays.asList(someStringArray));
for (int i = 7; i < contentStrToPrint.size(); i += 7) {
for (String aSomething : something) {
if (contentStrToPrint.get(i).contains(aSomething)) {
StringBuilder summary = new StringBuilder();
for (int j = i; j < i + 7; j++) {
row.add(contentStrToPrint.get(j));
if (j != i + 6)
summary.append(contentStrToPrint.get(j)).append("#");
else
summary.append(contentStrToPrint.get(j));
}
data.add(row);
Calc.summary.addInfo(Calc.writer, summary.toString());
row = new Vector<>();
}
}
}
I know it's not the neatest code. As a result I get empty "SummaryN.csv" file. I can't see a mistake here; moreover, I recreated this in Test project - much simpler, only writing Strings from given ArrayList (also being made from given String[]) on buttonClick - and it works. Also, printing out values at any possible stage returns proper Strings. Is it possible to be somehow (I have no idea how) be connected with the threaded method?
Any help would be much appreciated!
PS The fun with Vectors is unimportant and needed in order to show some values.