Salve a tutti,
nella classe che ho creato mi compare il seguente errore:
Exception in thread "main" java.lang.NullPointerException
at synthetic.binary.SintheticBinarySpectrum.main(Sint heticBinarySpectrum.java:43)
dove al classe incriminata è:
codice:
import tools.exception.Exception;
import tools.numeric.interpolation.*;
public class SpectrumInterpolation
{
private double [] totalflux;
private double[] lambda;
private double[] flux1;
private double[] flux2;
private double shift;
public SpectrumInterpolation (double[]l, double []f1, double []f2, double s)
{
lambda=l;
flux1=f1;
flux2=f2;
shift=s;
}
public void Interpolation () throws Exception
{
totalflux = new double[lambda.length];
double step;
double points;
double [] newlambda = new double[lambda.length];
double [] newflux2 = new double[lambda.length];
for( int i=0; i<lambda.length ; i++)
{
newlambda[i] = lambda[i] + shift;
}
step=lambda[2]-lambda[1];
points=shift/step;
//Interpolation
Interpolator f = new LinearInterpolator();
f.setSample(lambda,flux2);
if (shift>0)
{
for (int i=0; i<lambda.length-points-1; i++)
//controllare per shift negativo
{
newflux2[i] = f.getValue(newlambda[i]);
}
}
//correzione punti inadatti
if (shift<0)
{
for(int j=0;j<points;j++)
{
newflux2[j] = 0 ;
flux1[j]=0;
}
}
else
{
for(int j=lambda.length-(int)points; j<lambda.length; j++)
{
newflux2[j] = 0;
flux1[j]=0;
}
}
//somma flussi
for (int i=0 ; i<lambda.length; i++)
{
totalflux[i]= flux1 [i] + newflux2[i];
System.out.println (newflux2[i]);
}
}
public double[] getSum()
{
return totalflux;
}
}
mentre la classe col main è questa:
codice:
import tools.exception.Exception;
import java.io.File;
public class SintheticBinarySpectrum {
static StarArgs StarMain = new StarArgs();
static StarArgs StarSecondary = new StarArgs();
public static void main(String[] args) throws Exception {
File file = new File("/lte100-3.5-0.0.spec");
ReadNextGenFile results = new ReadNextGenFile(file);
StarMain.Teff = results.getTeff();
StarMain.logg = results.getlogg();
StarMain.Met = results.getMet();
StarMain.Spectrum.lambda = results.getLambda();
StarMain.Spectrum.flux = results.getFlux();
File file2 = new File("/lte100-2.0-0.0.spec");
ReadNextGenFile results2 = new ReadNextGenFile(file2);
StarSecondary.Teff = results2.getTeff();
StarSecondary.logg = results2.getlogg();
StarSecondary.Met = results2.getMet();
StarSecondary.Spectrum.lambda = results2.getLambda();
StarSecondary.Spectrum.flux = results2.getFlux();
StarMain = StarData.setPar(0.8, 1.e8);
StarSecondary = StarData.setPar(1.8, 1.e8);
SpectrumInterpolation Interpolation = new SpectrumInterpolation(
StarMain.Spectrum.lambda, StarSecondary.Spectrum.flux,
StarMain.Spectrum.flux, 5.5);
for (int i = 0; i <= StarMain.Spectrum.lambda.length - 1; i++) {
System.out.println("Total flux (" + i + ")= "+ Interpolation.getSum()[i]);
}
}
}
l'errore compare in quest'ultimo ciclo for quando invoco getSum().
Chi mi sa dire dove sbaglio?