Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

using superCSV to read data: Getting "java.lang.NoSuchMethodException"  RSS feed

 
Nimu Chox
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Any help is really appreciated


CSV file:

Warehouse ID,Manufacturer,Model,Processor,Memory,PCI buses,PCI-X busses,PCI-express busses
4611,HP,Proliant DL380,x86 Xeon,1G,1,3,0



Main class:


[Rob]split long line[/]
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The method is setWarehouseID(int) but superCSV is trying to call setWarehouse ID(String) - with space and using int instead of String.
 
Nimu Chox
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.

Why is SuperCSV bahaving that way?: I want is to see it setWarehouseID(int) . Please bear with me, I using this API today for the first time. I have tried to read it using New ParseInt();

Also I am wondering how can I read the files with headers consisting spaces i.e. "#Datawarehouse ID", "PCI bus" using the CSV reader; I dont want to change the header names in my CSV files.

Please advice
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The second argument to the read method indicates the property names. This is the setter method without the set part, like WarehouseID. You pass the contents of the CSV file's first row, which includes Warehouse ID. You need to supply the actual property names instead, like WarehouseID, NumOfPciBus, etc.

The third argument indicates the CellProcessor instances to use for converting the Strings to something else. In your original code you had all null values, which meant no conversion. The ParseInt you mentioned will convert the Strings to ints instead.
 
Nimu Chox
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I changes the headers to match the variable names... but now I get this exception:





[Rob]split long line of code[/]
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You provide 8 CellProcessors. Does your CSV file also have 8 columns?
 
Nimu Chox
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, My Csv file has 8comlumn


 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see the problem. The CsvPreference you use does not use commas as column separators but semicolons. As a result, SuperCSV sees your 8 columns as only 1. Try one of the other CsvPreference constants, or create one yourself.
 
Nimu Chox
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I changed my own : CsvPreference pref = new CsvPreference('"', ',', "\n");
and also I tried this one: CVS prefence to EXCEL_PREFERENCE,

but I still get this exception:

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!