このエラーが発生しました。プログラムが基本的に .txt ファイルを読み取って配列に保存する理由がわかりません。どんな助けでも大歓迎です。
error message:Exception in thread "main" java.lang.NoClassDefFoundError: song (wrong name: Song)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
コード:
import java.util.*;
import java.lang.*;
import java.io.*;
import java.nio.charset.*;
class Song {
private int songId; // The unique song identifier
private String title; // The song title
private String artist; // The song artist
private String genre; // The genre of the song
private String album; // The album name
private String songData;
public Song(int songId, String title, String artist, String genre,
String album, String songData) {
this.songId = songId;
this.title = title;
this.artist = artist;
this.genre = genre;
this.album = album;
this.songData = songData;
}
public String toString() {
return "Id: " + songId + ", Title: " + title + ", Artist: " + artist +
", Genre: " + genre + ", Album: " + album + ", Data: " + songData;
}
}
class Ideone {
public static void main (String[] args) throws java.lang.Exception {
try {
FileInputStream fstream = new FileInputStream("songCollection.txt");
// use DataInputStream to read binary NOT text
// DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine;
while ((strLine = br.readLine()) != null) {
String[] splitOut = strLine.split(", ");
for (String token : splitOut)
System.out.println(token);
}
in.close();
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
Readable fileSong;
String[] songData = new Scanner(fileSong);
while (songData.hasNextLine()) {
String songCollection = songData.nextLine();
songData = songCollection.split(",");
List<Song> songs = new ArrayList<>();
try (BufferedReader input = new BufferedReader(new InputStreamReader(
System.in, Charset.forName("UTF-8")))) {
String line;
while ((line = input.readLine()) != null) {
String[] arr = line.split(",");
songs.add(new Song(Integer.parseInt(arr[0]), arr[1], arr[2],
arr[3], arr[4], arr[5]));
}
} catch (IOException e) {
e.printStackTrace();
}
for (Song song : songs) {
System.out.println(song.toString());
}
}
}