From: Randolph Wang <rywang@CS.Princeton.EDU>
Date: Tue, 30 Mar 2004 11:32:50 -0500 (EST)
To: allisonl@Princeton.EDU
Cc: randy_class@CS.Princeton.EDU
Subject: Re: appointment to meet

>  My question was about the Wave.add function--I don't think we are 
>  returning the wave correctly or something because we are getting 
>  nullpointerexception when we try to run it. Do you see what is wrong 
>  with it? (I attached Wave.java) 



>  public Wave (double Hz, double seconds, double amplitude) { 
>     this.N = (int)seconds*44100; 
>     this.left = new short[N]; 
>     this.right = new short[N]; 
>     for (int i = 0; i<N; i++) { 
>  	 this.left[i] = (short)((amplitude * Math.sin(2* Math.PI * Hz * i/ 44100))); 
>  	 this.right[i]= (short)((amplitude * Math.sin(2* Math.PI * Hz * i/ 44100))); 
>  	} 
>  } 
>  		 
>  public Wave (short[] L, short[] R) { 
>  	this.N = L.length; 
>  	for (int i = 0; i<N; i++) { 
>  			this.left[i]=L[i]; 
>  			this.right[i]= R[i]; 
>  	} 
>  	 
>  } 

A not-so-subtle hint :)

In the first constructor, you correctly allocated new space for
this.left and this.right, but in the second constructor...


----------------------------------------------------------------------

BTW, about debugging:

(1) When you got the null pointer exception, the error message should
    have said something about the line number of the line where the
    error occurred.  You should pay attention to that information.

(2) At some point, you might want to give the debugger that I showed
    you yesterday a try.  Had you stepped through the debugger one
    line at a time, it'll take no time to pinpoint the location of
    some errors.

Randy


Re: appointment to meet / Randolph Wang