0
java実行エラー
package java9_2;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;
import javax.sound.midi.MidiChannel;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Synthesizer;
public class finalreport {
public static void main(String[] args) {
String str;
long[] time = new long[113];
int[] chan = new int[113];
int[] note = new int[113];
int[] vel = new int[113];
int timenum = 0,channum = 0,notenum = 0,velnum = 0,count = 0;
try {
FileReader fr= new FileReader(args[0]);
BufferedReader br = new BufferedReader(fr);
while ((str = br.readLine()) != null) {
// 入力バッファから一行読み込み
StringTokenizer st = new StringTokenizer(str);
// StringTokenizer を作成(空白で分離)
while (st.hasMoreTokens()) {
// まだトークンが残っている場合
String tmp=st.nextToken();
// 次のトークンを得る
count++;
if(count % 4 == 1){
if(timenum != 0){
time[timenum] = Long.parseLong(tmp);
}
timenum++;
}else if(count % 4 == 2){
if(channum != 0){
chan[channum] = Integer.parseInt(tmp);
}
channum++;
}else if(count % 4 == 3){
if(notenum != 0){
note[notenum] = Integer.parseInt(tmp);
}
notenum++;
}else{
if(velnum != 0){
vel[velnum] = Integer.parseInt(tmp);
}
velnum++;
}
}
}
br.close();
} catch (FileNotFoundException e) {
System.err.println("ファイルが開けません");
} catch (IOException e) {
System.err.println("入出力エラーがあります");
}
MidiChannel[] channel;
Synthesizer synthesizer;
try {
synthesizer = MidiSystem.getSynthesizer();
// シンセサイザの取得
} catch (MidiUnavailableException e) {
System.err.println("MIDIシステムが利用できません");
return;
}
try {
synthesizer.open();
// シンセサイザを開く
} catch(Exception e){
System.err.println("MIDIデバイスが開けません");
return;
}
channel = synthesizer.getChannels();
// チャンネル配列を取得(通常16チャンネル同時再生可能)
// 音色を変化 0-127 (General MIDIの番号は1-128)
channel[0].programChange(49);
// チャンネル0の音色は弓弦楽器合奏音1
channel[1].programChange(44);
try {
Thread.sleep(500);
// マシンによっては冒頭の音が切れることがあるのでわずかに待機
long start = System.nanoTime();
// 開始時刻の取得(ナノ秒単位)
long now;
// 時刻用(ミリ秒単位)
// 以下は楽譜データ(4つの配列が関連している)
// time: MIDIメッセージを送信する時刻
// note: 音高
// vel: 音量)
// chan: チャンネルによって楽器を区別する
int i=1;
LOOP:
while (true) {
// 無限ループ(配列のデータがなくなったらbreak)
now = (System.nanoTime()-start)/1000000L;
// 現在時刻を計算(ミリ秒単位)
while (now>=time[i]) {
// 現在時刻を過ぎたイベントがある場合はそれらをすべて出力
channel[chan[i]].noteOn(note[i], vel[i]);
// chan[i]チャンネルに音高note[i]、音量vel[i]で
// ノートオンメッセージ送信
System.out.println(now+","+chan[i]+","+note[i]+","+vel[i]);
// 画面にログ出力
i++;
if (i>=time.length) break LOOP;
// 配列をすべて読み終わったら、二重無限ループを抜ける
}
Thread.sleep(1);
// 1ミリ秒スリープ
}
} catch(Exception e){
System.err.println("エラーが発生しました。");
if(channel[0] != null) channel[0].allNotesOff();
} finally {
synthesizer.close(); // 例外時も含め、シンセサイザをクローズ
}
}
}
コンパイルはできるんですが、実行すると
Exception in thread "main" java.lang.NumberFormatException: For input string: "600,40,79,2"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:589)
at java.lang.Long.parseLong(Long.java:631)
at java9_2.finalreport.main(finalreport.java:44)
と出てきます。
解決するにはどうすればいいでしょうか