import org.jfugue.player.Player;
public class MusicPlayer {
public static void main(String[] args) {
TwelveBarBlues twelveBarBlues = new TwelveBarBlues();
System.out.println("Twelve Bar blues Playing: ");
Player player = new Player();
player.play(twelveBarBlues.getPattern());
}
}
import java.io.IOException;
import org.jfugue.pattern.Pattern;
import org.jfugue.player.Player;
import org.jfugue.theory.ChordProgression;
public class TwelveBarBlues {
private String pattern;
public static void main(String[] args) throws IOException {
Pattern pattern = new ChordProgression("I IV V")
.distribute("7%6")
.allChordsAs("$0 $0 $0 $0 $1 $1 $0 $0 $2 $1 $0 $0")
.eachChordAs("$0ia100 $1ia80 $2ia80 $3ia80 $4ia100 $3ia80 $2ia80 $1ia80")
.getPattern()
.setInstrument("Acoustic_Bass")
.setTempo(100);
new Player().play(pattern);
}
public String getPattern() {
this.pattern = pattern;
return pattern;
}
}
I want to play the twelveBarBlue music code at MusicPlayer. but I got error code Cannot invoke "java.lang.CharSequence.length()" because "this.text" is null when I run the MusicPlayer MusicPlayer Error Code
When you execute MusicPlayer, it calls
main()in MusicPlayer butmain()in TwelveBarBlues is never called, so ingetPattern(), 'pattern' has never been set, and you're returning null.Instead, change TwelveBarBlues so
getPattern()returns the pattern that you currently have inmain(). Just move the code frommain()intogetPattern(), then remove themain()method, since you're not running TwelveBarBlues as its own program.Or, keep the
main()method in case you want to use that class as its own executable, but have it call its owngetPattern()method. You'll need to do something likeTwelveBarBlues blues = new TwelveBarBlues();and thennew Player().play(blues.getPattern());.