I have this following class to be Serialized.
Code
public class Instrument implements Serializable
{
private List <Touche> listTouche;
private Timbre timbre;
private Image background;
private DisplayTouche disTouche;
private LoopPedal[] arrayLoopPedal;
private String name;
private Touche currentTouche;
private boolean playMode;
private SoundGenerator sGenerator;
}
public class SoundGenerator implements Serializable{
private Timbre timbre;
private transient Synthesizer synth;
private transient MidiChannel[] chan;
private transient Instrument[] inst;
/* public SoundGenerator()
{
} */
static final private int[] instValues = new int[]{33, 58, 25, 17, 112, 0, 80, 91};
public SoundGenerator(Timbre timbre) throws javax.sound.midi.MidiUnavailableException {
synth = MidiSystem.getSynthesizer();
synth.open();
chan = synth.getChannels();
try {
File bank = new File("src/Gaudrophone/domain/sound/soundbank.sf2");
inst = MidiSystem.getSoundbank(bank).getInstruments();
}
catch (InvalidMidiDataException | IOException exception) {
inst = synth.getDefaultSoundbank().getInstruments();
}
this.setTimbre(timbre);
}
public void setTimbre(Timbre timbre) {
chan[0].programChange(instValues[timbre.ordinal()]); /****************** null pointer exception here**********************/
}
public void generateSound(Sound sound) {
chan[0].noteOn(sound.getMidiNumber(), 200);
}
public void stopSound(Sound sound) {
chan[0].noteOff(sound.getMidiNumber());
}
}
The problem is that I cant serializable the SoundGenerator class. I tried to put attributes transcend, but when I have to deserialize, I got a nullPointerException .
thx 4 the help