-1

I m new to java and using Netbeans IDE for my project. I need to read and display csv files so i used opencsv library for that. it is working fine on my computer but the jar file is not able to load any csv file on a different machine. what could be the reason? what should I do to resolve this problem?

code for reading csv file

try{

   CSVReader reader = new CSVReader(new FileReader(dataFile));       
   String [] nextLine;
   row = 0;
   ArrayList<String[]> ls = new ArrayList<>(); 

   while ((nextLine = reader.readNext()) != null) {
            row++;
            ls.add(nextLine);             
   }       
   col=ls.get(0).length;
   String[] tempHeader=new String[col];            
   for(int i=0;i<col;i++)
   tempHeader[i]=(String)("ATT"+(i+1));
   fileData=new String[row][col];
   for(int i=0;i<ls.size();i++)
   fileData[i]=ls.get(i);
   DefaultTableModel dm = new DefaultTableModel();     
   dm.setDataVector(fileData,tempHeader);
   previewTable.setModel(dm);
   } catch(IOException e){}

this is working on my machine. But the jar file which i send to my friend is not able to display the file.

user3181652
  • 34
  • 1
  • 5
  • print the error stack please! – Rugal Jan 10 '14 at 12:09
  • We would need some code to see what you are doing in order to help. – mikea Jan 10 '14 at 12:09
  • What error do you get exactly ? If it is FileNotFoundException, you may have a problem in your paths. – Olivier Croisier Jan 10 '14 at 12:10
  • Maybe you didn't properly code the path for the file location and in different machines, it's different? – Sajal Dutta Jan 10 '14 at 12:10
  • 1
    I send the .jar file of my project to my friend and he is complaining that it is not working. it is not able to load any csv file. but on my machine it is working perfectly fine.loading and displaying the csv files. what changes i have to make so that it also work on different machines – user3181652 Jan 10 '14 at 12:18

1 Answers1

0

The easiest way to see what's wrong is to add some debug information.

First of all, you are catching the IOException but do nothing in the catch block. With this implementation, if there is some problem while reading the file on your friends system (i.e. the IOException is thrown), no error output is written. You just throw away the exception. At least add some e.printStackTrace() within the catch block to output the stack trace to the console.

Then, you could add some (temporary) debug information inside the while loop, e.g. System.out.println(nextLine). This would output each line read from the CVV file.

(A better way would be to use a logging library like Log4J but the suggestion above should do it in your case)

Finally, make sure your friend starts the jar file from the command line (and not by double-clicking on the jar file!). The error stack trace and debug information should be displayed in the command window.

Dominic
  • 4,572
  • 3
  • 25
  • 36