Results 1 to 6 of 6

Thread: Read CSV file

  1. #1
    minama's Avatar
    minama is offline Member
    Join Date
    Dec 2011
    Posts
    9
    Rep Power
    0

    Unhappy Read CSV file

    Hello,

    I'm pretty new in Java, I try to read csv file into Data class. I use superCsv, but I have an error :(
    Java Code:
    Error while filling an object context: null offending processor: null
    	at org.supercsv.io.CsvBeanReader.fillObject(Unknown Source)
    	at org.supercsv.io.CsvBeanReader.read(Unknown Source)
    	at dataLoader.ReadFile.loadFromCSV(ReadFile.java:36)
    	at main.Program.main(PPR.java:16)
    Caused by: java.lang.InstantiationException: data.Data
    	at java.lang.Class.newInstance0(Unknown Source)
    	at java.lang.Class.newInstance(Unknown Source)
    	... 4 more
    Java Code:
    	Locale.setDefault(Locale.US);
    				
    		CsvPreference pref = new CsvPreference(';', ';', ";");
    		FileReader fr = new FileReader(csvfile);
    		ICsvBeanReader inFile  = new CsvBeanReader(fr, pref);
    			
    		try{
    		
    			Data data;
    			String[] header = inFile.getCSVHeader(true);			
    			
    			while((data = inFile.read(Data.class, header, processors))!=null){
    				
    				System.out.println(data.getTime());
    				System.out.println(data.getVal1());
    				
    			}
    			
    			
    		}
    		
    		finally{
    			inFile.close();
    		}
    		
    	}
    	
    	static CellProcessor[] processors = new CellProcessor[]{
    			
    			new ParseDate("HH:mm:sss"),
    			new StrMinMax(1,30), //value 1,
    			null, // value 2
    			new StrMinMax(0, 20)// value 3
    	};
    actually value 1,2,3 are double, but I have error when I try to use ParseDouble, may be because values in CSV file has the following format #,#####.
    Thank you.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default Re: Read CSV file

    For a moment change the content and give a try with a dummy file. Then you can make sure it. Since the exception you ends with not provide much details, seems that is the best way.

  3. #3
    minama's Avatar
    minama is offline Member
    Join Date
    Dec 2011
    Posts
    9
    Rep Power
    0

    Default Re: Read CSV file

    Oh, I've solved the problem, I used EXCEL_NORTH_EUROPE_PREFERENCE and it worked, and one of the name of the columns was with capitals "VA", but I had setVa, while setVA is correct. Anyway, Thnx a lot. :)

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default Re: Read CSV file

    You are welcome (even I have not really helping you to solve the problem)

    However, thanks a lot for posting that the way you solved it. There may be other members in the forums that stuck with the same issue.

Similar Threads

  1. Replies: 1
    Last Post: 08-05-2011, 09:21 PM
  2. Replies: 2
    Last Post: 05-11-2009, 10:07 AM
  3. Replies: 0
    Last Post: 02-11-2009, 09:53 AM
  4. Replies: 5
    Last Post: 02-05-2009, 10:28 AM
  5. How to read a text file from a Java Archive File
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-08-2008, 09:13 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •