Basically I want to encapsulate all the MW Builder JA stuff in a separate class.
import com.mathworks.toolbox.javabuilder.*;
import com.widelane.SpecAnalysis.*;
public class SpectralAnalysis {
public double nSamples = 1001.0;
public double interval = 0.01;
public double[] t = null;
public double[] data = null;
public double[] freq = null;
public double[] powerSpec = null;
public SpectralAnalysis(double nSamples,double interval){
this.nSamples = nSamples;
this.interval = interval;
}
public SpectralAnalysis(){
this.nSamples = 1001.0;
this.interval = 0.01;
}
public void computeFFT(){
WLSpecAnalysis specAnalysis = null;
Object[] results = null;
try {
specAnalysis = new WLSpecAnalysis();
results = specAnalysis.dofft(4, this.nSamples, this.interval);
this.t = (double[])((MWArray)results[0]).getData();
this.data = (double[])((MWArray)results[1]).getData();
this.freq = (double[])((MWArray)results[2]).getData();
this.powerSpec = (double[])((MWArray)results[3]).getData();
} catch (MWException e) {
e.printStackTrace();
}finally{
MWArray.disposeArray(results);
if (specAnalysis != null){
specAnalysis.dispose();
}
}
}
public static void main(String[] args){
// THIS WORKS
SpectralAnalysis sa = new SpectralAnalysis();
sa.computeFFT();
System.out.println(sa.freq.length);
System.out.println(sa.powerSpec.length);
}
}
When I use the class in the main method everthing is fine but when i create a new class that would like to make an instance of the class SpectralAnalysis i get bunch of compiler errors?!? This seems so basic :( What am I doing wrong?
public class TestClass {
static void main(String[] args) {
//THIS DOES NOT WORK????
SpectralAnalysis sa = new SpectralAnalysis();
sa.computeFFT();
System.out.println(sa.freq.length);
System.out.println(sa.powerSpec.length);
}
}
Exception in thread "main" java.lang.ExceptionInInitializerError at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration.getProxyLibraryDir(MCRConfiguration.java:163) at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration$MCRRoot.get(MCRConfiguration.java:77) atcom.mathworks.toolbox.javabuilder.internal.MCRConfiguration$MCRRoot.<clinit>(MCRConfiguration.java:87)at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration.getMCRRoot(MCRConfiguration.java:92)at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration$ModuleDir.<clinit>(MCRConfiguration.java:66)at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration.getModuleDir(MCRConfiguration.java:71)at com.mathworks.toolbox.javabuilder.internal.MWMCR.<clinit>(MWMCR.java:1573) com.widelane.SpecAnalysis.SpecAnalysisMCRFactory.<clinit>(SpecAnalysisMCRFactory.java:123)at
com.widelane.SpecAnalysis.WLSpecAnalysis.<init>(WLSpecAnalysis.java:84)
at SpectralAnalysis.computeFFT(SpectralAnalysis.java:42)
at TestClass.main(TestClass.java:9)
Caused by: java.lang.NullPointerExceptionat com.mathworks.toolbox.javabuilder.internal.MCRConfiguration$ProxyLibraryDir.get(MCRConfiguration.java:143)at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration$ProxyLibraryDir.<clinit>(MCRConfiguration.java:158)
... 11 more