osiegmar/FastCSV

"NoSuchMethodError" Exception is thrown while saving to csv

sodiqOladeni opened this issue · 1 comments

@osiegmar
Unable to save to csv due to exception, below is my stack trace and my code.
No virtual method toPath()Ljava/nio/file/Path; in class Ljava/io/File;

if (entityList.size() > 0) {

                File storageDir = new File(Environment.getExternalStorageDirectory() + "/"
                        + this.getString(R.string.app_name));

                boolean success = true;
                if (!storageDir.exists()) {
                    success = storageDir.mkdirs();
                }

                if (success) {

// String baseDir = getExternalStorageDirectory().getAbsolutePath();
// String filePath = baseDir + "/" + "Demo.csv";
File file = new File(storageDir, "contacts.csv");
CsvWriter csvWriter = new CsvWriter();
Collection<String[]> data = new ArrayList<>();
for (ContactEntity d : entityList) {
data.add(new String[]{"Name", "Phone Number"});
data.add(new String[]{d.getName(), d.getName()});
}
try {
csvWriter.write(file, StandardCharsets.UTF_8, data);
Log.v(TAG, "csv file created");
} catch (IOException e) {
e.printStackTrace();
}
}else {
Toast.makeText(this, "Directory not exist", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(this, "No data to export csv", Toast.LENGTH_SHORT).show();
}

I guess, you're using Android, not Java. Please see #3.