How to solve a problem related to the implementation of the legacy?

Hello

Then I come on this way to ask for assistance on the implementation of the legacy on my request. So the problem is:

I apply I need to capture audio and analyzing this capture of the Spectrum Analyzer, Volumes etc.

So I will use several microphones in this application, I will use the same code in the audio capture.

I have a class called Application which has GUI and events, such as events of button and update the values in the GUI. In my first version of the Application, I have everything here, but I had Don t like that and is not good for performance, so I want to divide the code by other classes. That's why I try to the legacy.

So I created a class called equipment which is the super class and in this class will have the method captureAudio(), the calculateRMSLevel(), the sendOutPresenceUpdates() etc... And I have 3 variables:
public abstract class Equipment {

    public AudioFormat format;
    public TargetDataLine line;
    public Mixer mixer;
    public EventListenerList listenerList = new EventListenerList();
    
    public Equipment(AudioFormat format, TargetDataLine line, Mixer mixer){

        this.format = format;
        this.line = line;
        this.mixer = mixer;
    }

    public AudioFormat getFormat() {
        return format;
    }

    public void setFormat(AudioFormat format) {
        this.format = format;
    }

    public TargetDataLine getLine() {
        return line;
    }

    public void setLine(TargetDataLine line) {
        this.line = line;
    }

    public Mixer getMixer() {
        return mixer;
    }

    public void setMixer(Mixer mixer) {
        this.mixer = mixer;
    }

     public int calculateRMSLevel(byte[] audioData){
     // audioData might be buffered data read from a data line
        long lSum = 0;
        for(int i=0; i<audioData.length; i++)
            lSum = lSum + audioData;

double dAvg = lSum / audioData.length;
double sumMeanSquare = 0d;
for(int j=0; j<audioData.length; j++)
sumMeanSquare = sumMeanSquare + Math.pow(audioData[j] - dAvg, 2d);

double averageMeanSquare = sumMeanSquare / audioData.length;
return (int)(Math.pow(averageMeanSquare,0.5d) + 0.5);
}

public void sendOutPresenceUpdates(int FullJIDAndResource, String NewPresence) {
     Object[] listeners = listenerList.getListenerList();

     Integer inputValue = _FullJIDAndResource;
     String convertedValue = inputValue.toString();
// Empty out the listener list
     // Each listener occupies two elements - the first is the listener class and the second is the listener instance
for (int i=0; i < listeners.length; i+=2) {
          if (listeners[i]==CustomPresenceListener.class) {
               ((CustomPresenceListener)listeners[i+1]).presenceEventOccurred(new CustomPresenceEvent(this, convertedValue, _NewPresence));
               }
          }
     }
public void listenForPresenceEvents(CustomPresenceListener _listener) {
          listenerList.add(CustomPresenceListener.class, _listener);
     }


public void removeEventListener(CustomPresenceListener _listener) {
          listenerList.remove(CustomPresenceListener.class, _listener);
     }
public void captureAudio(){

}
And i have questions about the constructor, is right the constructor that i created in the superclass?

So i create a subclass called Microphone1 and in this class i make override from the method captureAudio() from the superclass and here i create the thread for the capture.
class Microphone1 extends material {}



Public Microphone1 (format AudioFormat, line TargetDataLine, drummer mixer) {}

Super (format, line, mixer);

}


public void captureAudio() {}
try {}
format = getFormat();
MixerInfo [] Mixer.Info = AudioSystem.getMixerInfo ();
DataLine.info get information on line.
DataLine.Info info = new DataLine.Info (TargetDataLine.class, format);
Drummer mixer = AudioSystem.getMixer(mixerInfo[3]);
Download the info from the desired line.
line = (TargetDataLine) AudioSystem.getLine (info);
Get a TargetDataLine on selected mixer.
line = mixer.getLine (info) (TargetDataLine);
Line.Open (format);
Line.Start ();

CaptureThread captureThread = new CaptureThread();
captureThread.start ();

} catch (Exception e) {}
System.out.println (e);
System.Exit (0);
} //end wrestling
}
But now i have a problem in the class Application, because i want to start the capture when i click in the button so i created the actionPerfomed and inside of this event i create this:
Microphone1 m1 = new Microphone1 (format, line, mixer);
M1.captureAudio ();
But when i execute the application and click in the button appears this: java.lang.NullPointerException :/ and i don't know how to solve this.

Any help? Where i am wrong?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

Well Yes, see also http://download.oracle.com/javase/tutorial/java/index.html

Tags: Java

Similar Questions

Maybe you are looking for

  • Satellite L50D-C - marketing questions

    I've had my Toshiba Satellite L50D-C since October 19, 2015 and almost day 1, I had problems turning on the laptop in standby mode. I press the power button and the led lights as the num snaps and caps lock lights up. The power light stays on as the

  • Portege M700-106: unable to start the task manager & programs after Vista sleep

    Hello In fact I am facing problem like below...Configuration: Portege M700-106 with upgrades (Hynix Kingston 4 GB, WD Scorpio 320 GB with jumper default config doesn't = no jumper)Reinstalled system from Toshiba DVD recovery, all updates possible on

  • Re: Satellite L10: cannot use the USB after XP Home recovery

    After Systemrecovery with the toshiba CD-ROM and install all updates for xp, there is no chance to use usb on somthething else keys. XP said ' you must intsaller a pilot ", but I do not know whichdriver. I don't think that in 98 I intsaller a driver?

  • If it is not recommended to burn DL iDVD projects?

    Hello When I want to save/record an as project DL iDVD project, iDVD says, one should not burn to / save as disc image, if you want to use DL media. Here, he also says that most stand-alone players will not play DL media http://www.peachpit.com/artic

  • transfer the app from iphone to itunes library

    Hello world.  I have an ios application that are not re - download in the app store specifically TUBE DOWNLOADER (D/L) by Apps2be. I don't know why this particular application has been removed in my itunes library.   I got a new Ipad pro and I want t