I am importing a large CSV w/many columns and selectively taking columns I need for my work. One of the columns is in 213.23 type formatting. I have tried multiple things to parse it but I am missing something or deleted something by accident and it did not get to git for some reason as it loaded the file properly once. Once imported I will export without all extraneous data I don't need. I think I am going to order up a second pair of eyes as this is an error I am missing and should see. There are Idea what I have tried below I am sure someone will quickly see the error. Any help you could offer; thanks in advance. Error first, class file and then manager below.
Error:
Exception in thread "main" java.lang.NumberFormatException: For input string: "duration"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
at java.lang.Double.parseDouble(Double.java:538)
at ch07.trees.SongManager.main(SongManager.java:98)
____________________________________________________________________________________________________ _
package ch07.trees;
import java.util.*; // Iterator, Comparator
import ch04.queues.*;
import ch02.stacks.*;
import support.BSTNode;
public class Song
{
String title;
String Artist;
String album;
double length;
String path;
public Song(String title, String Artist, String album, double length, String path)
{
this.title=title;
this.Artist=Artist;
this.album=album;
this.length=length;
this.path=path;
}
}
________________________________________________________________________________________
package ch07.trees;
import java.util.*; // Iterator, Comparator
import java.io.*;
import ch04.queues.*;
import ch02.stacks.*;
import support.BSTNode;
public class SongManager
{
BinarySearchTree<Song> mytree=new BinarySearchTree<Song>();
public SongManager(){
this.mytree=new BinarySearchTree<Song>();
}
public static void main(String args[]){
SongManager mang=new SongManager();
Scaer kb=new Scaer(System.in);
String command=kb.nextLine();
if (command.equals("--load")){
String csvFile = "/Rick/bookFiles/ch07/trees/SongData.csv";
BufferedReader br = null;
String line = "";
String cvsSplitBy = ",";
try {
br = new BufferedReader(new FileReader(csvFile));
while ((line = br.readLine()) != null) {
// use comma as separator
String[] row = line.split(cvsSplitBy);
System.out.println("Artist = " + row[2] + " , Album=" + row[21] + " ,
title=" + row[34]+ " , length=" + row[9]+ " , loc=" + row[15] );
String title,Artist,AlblumTitle,path;
Double ms;
//tried both Double and double neither worked!!
//double ms
title=row[34];
Artist=row[2];
AlblumTitle=row[21];
//Tried all three and did not work and also tried parsing above in System.out.println row[9].
ms=new Double(row[9]);
//ms = Double.parseDouble(row[9]);
//ms=row[9];
path=row[15];
Song s=new Song(title, Artist, AlblumTitle, ms, "path");
mang.mytree.add(s);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
}
برچسب:
نویسنده: آیلین رضوانی
تاريخ: يکشنبه
12 آذر
1396 ساعت: 19:12