osiegmar / FastCSV

CSV library for Java that is fast, RFC-compliant and dependency-free.
https://fastcsv.org/
MIT License
551 stars 93 forks source link

"NoSuchMethodError" Exception is thrown while saving to csv #26

Closed sodiqOladeni closed 6 years ago

sodiqOladeni commented 6 years ago

@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(); }

osiegmar commented 6 years ago

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