can not resolve symbol

can not resolve symbol

Page 1 of 1

1 Replies - 1606 Views - Last Post: 21 October 2006 - 12:44 PM Rate Topic: -----

#1 checkerbum2  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 20-October 06

can not resolve symbol

Posted 20 October 2006 - 11:48 PM

When I compile the code below, I get a compile error -
can not resolve symbol - freqIn on line 203.
I have no clue on how to fix this problem.
Or why I have this problem.

freqIn is defined in Freq object.

Thanks for any help I get.
and god bless,

Andy
//: EnhancedRateMult.java
/** 
* EnhancedRateMult Class
* @author andrew kameya
* @author andrew.kameya@skyworksinc.com
* @version 0.0
* @since 2006-08-31
* @since java version se5
* 
* @see printHeader method - for information you would normally find here.
*
*   Main							// defines order methods are executed
*	  openOut					  // opens an ouput file if needed
*	  printHeader				  // prints header (the documentation)
*	  readIn					   // reads inFile, creates Freq objects
*	  writeResults				 // write the results
*
*		 readIn creates Freq objects based on input data.
*			Freq objects uses
*			   gcd				 // finds the greatest common divisior
*			   findRateBitsRev	 // finds corrected numerator rate bits
*
*/
// helper methods in alpha order
//	  bitsInLong				   // counts bits in long
//	  longToDec					// long int to dec string with commas
//	  longToHex					// long int to hex string with spaces 
//	  reverseBits				  // reverses bits
//	  sizeOfDec					// size of int in Dec representation
//	  sizeOfHex					// size of int in Hex representation
//	  toLongPos					// converts string to long positive
//	  writeOut					 // writes output
///////////////////////////////////////////////////////////////////////////////
import java.io.*;
import java.util.*;
import java.lang.reflect.Field;
///////////////////////////////////////////////////////////////////////////////
public class EnhancedRateMult {
/** Enry point to class and application
*@param Infile and optionally OutFile
*@throws  FileNotFoundException, IOException
*/

///////////////////////////////////////////////////////////////////////////////
   static PrintWriter outPW = null;			//output handle   
   static void openOut(String [] args)throws IOException{
/** openOut method
*@param String [] args
*@throws IOException
* uses: NULL
*@returns PrintWriter outPW //a static output handle
*/
///////////////////////////////////////////////////////////////////////////////
// optionally, opens output file 
	  if (args.length == 2) { //if specified, open print writer
		 outPW = new PrintWriter(new BufferedWriter(new FileWriter(args[1])));
	  }
	  return;
   } // end openOut

///////////////////////////////////////////////////////////////////////////////
   static void printHeader(){// Program header and program documentation
/** printHeader method
*@param None
*@throws  No exceptions
* uses: writeOut helper
* outputs header and usage info.
*/
   writeOut( 
	  "																	 \n"+
	  "				ENHANCED RATE MULTIPLIER							 \n"+
	  "					  2006 June 06								   \n"+
	  "					Andrew M. Kameya								 \n"+
	  "																	 \n"+
	  " Purpose:															\n"+
	  "	The Enhanced rate multiplier creates any frequency from another  \n"+
	  "	frequency in a systematic manner.  Rate multipliers are also	 \n"+
	  "	known as pulse swallowers, so the output frequency is less than  \n"+
	  "	(or equal to) the input frequency.  The Enhanced Rate Multiplier \n"+
	  "	is an enhanced binary rate multipler where the denominator can be\n"+
	  "	any value, i.e. not restricted to be a power of 2.			   \n"+
	  "	A good reference for binary rate multipliers is the TTL		  \n"+
	  "	7497 device - (data sheet on the web).						   \n"+
	  "																	 \n"+
	  "	This program assists in programming the Enhanced Rate Multiplier,\n"+
	  "	but does not cover the case where the input and output frequencies\n"+
	  "	are the same.													\n"+
	  "																	 \n"+
	  "  Usage (on DOS command line):									   \n"+
	  "	java EnhancedRateMult  [Infile]  [Outfile]					   \n"+
	  "	  default Infile  is freq.dat									\n"+
	  "	  default Outfine is freq.out									 \n"+
	  "																	 \n"+
	  "	where Infile is an input file which has a list of desired input  \n"+
	  "	and output frequency pairs.  See example freq.dat file.		  \n"+
	  "																	 \n"+
	  "	input freq > output freq										 \n"+
	  "	input freq and output freq must be less than or equal to		 \n"+
	  "	(2 ** 63) - 1 or 9,223,372,036,854,775,807					   \n"+
	  "																	 \n"+
	  "	Non-valid input pairs are treated as comments					\n"+
	  "																	 \n"+
	  "	The input processing terminates when the input frequency = 0	 \n"+
	  "			 or EOF.												 \n"+
	  "																	 \n"+
	  "  Compiled with Java SE5 (may not compile with earlier versions)	 \n"+
	  "																	 \n"+
	  "/////////////////////////////////////////////////////////////////////\n"+
	  "This program was written with GVIM and in the same spirit as GVIM,   \n"+
	  "a great charity-ware editor.										 \n"+
	  "																	 \n"+
	  "If this program is of value to you and you feel moved to respond,	\n"+
	  "please donate to a children of Africa charity.					   \n"+
	  "																	 \n"+
	  "One tax deductible charity is the									\n"+
	  "   IRVINE PRESBYTERIAN MISSION, AFRICAN CHILDRENS FUND.			  \n"+
	  " 	4445 Alton Parkway, Irvine, CA 92604						\n"+
	  "		 (949) 786-9627											  \n"+
	  "																	 \n"+
	  "Be assured that 100% of the donation will aid the children of Africa.\n"+
	  "The missions committee is staffed by volunteers.  Irvine Presbyterian\n"+
	  "operating budget is separate and is funded by members of Irvine	  \n"+
	  "Presbyterian Church.												 \n"+
	  "");

	  return;

   } //end printHeader

///////////////////////////////////////////////////////////////////////////////
//Maxs are initialized by compiler to 0.  
//Maxs are used for formatting
   static long freqInMax	; //largest freqIn
   static long freqOutMax   ; //largest freqOut
   static long denominatorMax; //largest denominator
   static long numeratorMax ; //largest numerator
   static long rateBitsRevMax; //largest rateBitsRev

   static int sizeFreqIn	;
   static int sizeFreqOut   ;
   static int sizeDenominator;
   static int sizeNumerator ;
   static int sizeDenomHex  ;
   static int sizeRateBitsRev;

/** class Freq
Used to hold input frequency pairs and results.
*/
   public class Freq {
//constructor
   Freq (long freqIn_, long freqOut_){
	 long freqIn	 , freqOut ;//input data
	 long denominator, numerator;//gcd removed
	 long rateBitsRev;		   //ratebits reversed

//input freq pair
	 freqIn  = freqIn_;
	 freqOut = freqOut_;

//compute results
	 long greatestCommonDenominator = gcd(freqIn, freqOut); //get gcd
	 denominator	  = freqIn /greatestCommonDenominator;
	 numerator		= freqOut/greatestCommonDenominator;

//find rate bits reversed   
	 rateBitsRev	  = findRateBitsRev(denominator, numerator);

/* show objects are created correctly
writeOut(" FreqIn	  = " + freqIn);
writeOut(" FreqOut	 = " + freqOut);
writeOut(" Denominator = " + denominator);
writeOut(" Numerator   = " + numerator);
writeOut(" RateBitsRev = " + rateBitsRev);
*/

//save max values for output formatting
	 freqInMax		= Math.max(freqInMax	 , freqIn);	  //
	 freqOutMax	   = Math.max(freqOutMax	, freqOut);	 //
	 denominatorMax   = Math.max(denominatorMax, denominator); //
	 numeratorMax	 = Math.max(numeratorMax  , numerator);   //
	 rateBitsRevMax   = Math.max(rateBitsRevMax, rateBitsRev); //
}// end constructor

// methods
//   public String toString(){return "" + freqIn;}
//   public String toString(){return "" + freqIn;}
//   public String toString(){return "" + this.freqIn;}
//   public String toString(){return "" + Freq.freqIn;}
//   public String toString(){return "" + EnhancedRateMult.freqIn;}
//   public String toString(){return "" + EnhancedRateMult.Freq.freqIn;}

 // toString method to printout objects  
//	 public String toString () {
//	 return (""
//		+longToDec(Freq.freqIn	   ,sizeFreqIn)
//	  +longToDec(freqOut		   ,EnhancedRateMult.sizeFreqOut)
//	  +longToDec(denominator	   ,EnhancedRateMult.sizeDenominator)
//	  +longToDec(numerator		 ,EnhancedRateMult.sizeNumerator)
//	  +longToHex((denominator-1)   ,EnhancedRateMult.sizeDonumHex)
//	  +longToHex(rateBitsRev	   ,EnhancedRateMult.sizeRateBitsRev)
//	  );	 
//   }// toString
	 public long getFreqIn(){return freqIn;};

}//Freq end

///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
   static void writeOut(String string){ 
/** writeOut
*@param   String string 
* writes to screen
* writes to file, if not null.
* writes are flushed to minimize debugging problems.
*@returns void
*/
///////////////////////////////////////////////////////////////////////////////	  
	  System.out.println(string); System.out.flush();
	  if (outPW != null) {
		 outPW.println(string); outPW.flush();
	  }
   } // end writeOut

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
   static int bitsInLong(long a){
/** bitsInLong
*@param   long a 
*@returns int (number of bits in long)
*/
///////////////////////////////////////////////////////////////////////////////
	  int bits=0;
	  while (a != 0) {
		 bits++;
		 a >>>= 1;//shift left, left fill with zero, not sign extention.
	  } 
	  return bits;
   }

///////////////////////////////////////////////////////////////////////////////
   static long findRateBitsRev (long denominator, long numerator){
/** findRateBitsRev
*@param   long denominator, long numerator
* precondition denominator   >   numerator (should have been previously tested)
*@returns long rateBitsRev (rate bits in reverse order).
*/
///////////////////////////////////////////////////////////////////////////////
	  int sizeDenom = bitsInLong(denominator);//need to know which bits are changing

	  long numeratorTrial = (1<<sizeDenom) * numerator / denominator;//starting point
	  // note: initial numeratorTrial is the correct value for a binary rate multiplier.
	  //	   but the enhanced rate multiplier counter does not count completely.
	  //	   hence, numerator trial must be increased till the correct ratio 
	  //	   is obtained.

	  long count;			 //allocation only
	  long numeratorTrialRev; //allocation only
	  
	  do {// until we find the correct answer (count).
		 //the reverse version of numerator Trial is needed for this calculation.
		 numeratorTrialRev = reverseBits(numeratorTrial, sizeDenom);
		  
		 count = 0;
		 for (long i = 1; i < denominator; i ++) {//"i = 0;" is okay too
			long temp = ((i ^ (i-1)) & i) & numeratorTrialRev;
			if (temp != 0) count++;  //count rate multiplier pulses
		 }//end for

		 if (count < numerator) {  //if count < numerator, increase numeratorTrial
			numeratorTrial += 1;//increase numerator trial
		 }
	  } while (count < numerator); // answer still wrong, try again.

	  if (count != numerator) writeOut
		 (" ERROR in ERM-count "+ count + " num "+numerator);
	  return numeratorTrialRev;
   }

///////////////////////////////////////////////////////////////////////////////
   static long gcd(long a, long b){
/** gcd - greatest common divider
*@param   long a, long b
*@returns long gcd
* uses Euclid's algorithm - recursive form
*			   also in non-recursive form (equivalent).
*/
///////////////////////////////////////////////////////////////////////////////
//   only a few (like 3, max = 11) recursions required for a solution
//recursive form of gdc
	  if (b == 0){
		  return a;
	  }
	  return gcd(b, a % b);
   }

//non-recursive form
//	  while (b != 0) {
//		 long remainder = a % b;
//		 a = b;		 
//		 b = remainder;
//	  }
//	  return a;
//   }

///////////////////////////////////////////////////////////////////////////////
   static long reverseBits(long a, int numBits){
/** reverseBits
*@param   long a, int numBits
*@returns long b (reversed bit order of a)
* numBits should be less than 64 (untested)
*   noExceptions thrown (add later).
*/
///////////////////////////////////////////////////////////////////////////////
	  //reverses the order of a
	  //preconditions - number of bits in a <= numBits
	  //postcoditions, return int "a" in reverse order, numBits.
	  long b = 0;
	  for (int i=0; i < numBits; i++) {
		 b <<= 1;	   //shift b left 1 bit
		 b += (a & 1);  //copy lsb of a to b
		 a >>>= 1;	  //move a down one (logical shift right)
	  }
	  return b;
   }

///////////////////////////////////////////////////////////////////////////////
   static long toLongPos(String string){
/** toLongPos
*@param   String string 
*
*@returns		 -1 string longer than 19 characters
*@returns		 -1 any non-numeric number.
*@returns	neg num 9,223,372,036,854,775,808 to
*@returns			9,999,999,999,999,999,999 because of rollover
*@returns	else 
*@returns positive long (valid positive long primative)
*@returns	0 to 9,223,372,036,854,775,807 // 2**63 -1,
*/
///////////////////////////////////////////////////////////////////////////////
	  long longOne = 0;
	  int len = string.length();
	  if (19 < len) {
	 longOne = -1;
	 return longOne;
	  }

	  for (int i=0; i < len; i++) {
		 char c = string.charAt(i);
		 if ('0' <= c && c <= '9') {
			longOne = longOne * 10 + (c - '0');
		 } else {
			longOne = -1;
			break;
		 } 
	  }
	  return longOne;
   }

///////////////////////////////////////////////////////////////////////////////
   public static int sizeOfDec(long num){
/** sizeOfDec
*@param   long num 
*
*@returns int, size of dec representation of num including commas
*/
///////////////////////////////////////////////////////////////////////////////
	  long temp = Math.abs(num); //not needed for this application
	  int sizeField = 0;

	  do {
		 sizeField ++;
		 temp /= 10;
	  } while (temp != 0);
	  sizeField += (sizeField -1)/3;	  //sizeField with comma
	  return sizeField;
   }

///////////////////////////////////////////////////////////////////////////////
   static int sizeOfHex(long num){
/** sizeOfDec
*@param   long num 
*
*@returns int, size of hex representation of num including spaces to break long numbers
*/
///////////////////////////////////////////////////////////////////////////////
	  long temp = Math.abs(num); //not needed for this application
	  int sizeField = 0;

	  do {
		 sizeField ++;
		 temp >>>= 4;
	  } while (temp != 0);
	  sizeField += (sizeField -1)/4;	//sizeField with spaces every four characters
	  return sizeField;
   }

///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
   static StringBuffer longToDec(long num, int sizeField){
/** longToDec
*@param long num, int sizeField 
* sizeFields defines field width.
* converts long to decimal string with leading blanks and commas
* precondition is sizeField must be large enough to hold digits, 
*	guarenteed by previous testing in this application.
*	this module is not intended for reuse without additional testing.
*@returns StringBuffer
*/
///////////////////////////////////////////////////////////////////////////////
	  StringBuffer string = new StringBuffer(sizeField); 
	  for (int i = 0; i < sizeField; i++) {
		 if (num == 0 && i != 0) {
			string.insert(0,' ');	//blank fill
		 } else {
			if (i % 4==3) {
			   string.insert(0,','); //add comma
			} else {
			   char c = '0';		 
			   c += num % 10;		//get digit
			   string.insert(0,c);   //add digits
			   num /= 10;			//next digit
			}
		 }
	  }
	  return string;
   }//StringBuffer

///////////////////////////////////////////////////////////////////////////////
   static StringBuffer longToHex(long num, int sizeField){
///////////////////////////////////////////////////////////////////////////////
	  //	returns StringBuffer of hex version of num
	  //preconditions - sizeField <= sizeOfHex(num)
	  //postconditions - returns StringBuffer - of hex version of num
	  StringBuffer string = new StringBuffer(sizeField);
	  for (int i = 0; i < sizeField; i++) {
		 if (num == 0 && i != 0) {
			string.insert(0,' '); //leading blank fill
		 } else {
			if (i % 5==4) {
			   string.insert(0,' '); //add space
			} else {
			   char c = '0';		 
			   long mod16 = num % 16;
			   c += mod16;		   //digits 
			   if (9 < mod16) {
				  c = 'A';
				  c += (mod16 - 10); //A-F when > 9
			   } //if mod16
			   string.insert(0,c);   //add Hex
			   num >>>= 4;		   //next four bits
			}//if else
		 }// if else
	  }//for
	  return string;
   }

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
   public static void main(String[] args)
	  throws FileNotFoundException, IOException{
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// create a container for Freq objects.
	  ArrayList freqs = new ArrayList();
	  
//prolog -- methods and helpers preceed main	  
	  openOut(args);	// open output first if specified
	  printHeader();	// display header - also to output file if specified

//afferent - create Freq objects	 
//   static void readIn(Freq freqs){
/** readIn - was a routine, but having trouble passing a pointer.
* so this design is flattened .. important that it works for now.
*@param   String [] args 
* opens input file and reads input data
* creates Freq object with each valid input and output freqs.
*	freqIn greater than freqOut to be valid input
*@returns void
*@throws  FileNotFoundException, IOException (if no input files)
*/
///////////////////////////////////////////////////////////////////////////////	 
//opens input file and reads input data
	  String fileIn;
	  if (args.length == 0) {// if not specified, use default
		 fileIn = "freq.dat";
	  } else { // else use specified name
		 fileIn = args[0];
	  }

//log the input file name - and create a buffered reader
	  writeOut("\n fileIn = " + fileIn);
	  BufferedReader in = new BufferedReader(new FileReader(fileIn));

//read inputs
	  String line, token;
	  StringTokenizer tokenizer;

	  while ((line = in.readLine())!= null) {
		 writeOut(line);	   //log input, including comments, for documenation
		 tokenizer = new StringTokenizer(line);
		 int tokenCount = tokenizer.countTokens();

		 if (1 < tokenCount) { //do if more than one token
			token = tokenizer.nextToken();

			// toLongPos returns negative number if not LongPos.
			long freqIn = toLongPos(token);   //convert first token
			if (0 < freqIn) {//do if
			  token = tokenizer.nextToken();//get next token
			  long freqOut = toLongPos(token);//save second token
			  if (0 < freqOut) {//do if 
				 if ( freqIn > freqOut){//create Freq object
//					freqs.add (new EnhancedRateMult.Freq(freqIn, freqOut)); //create Freq object
				 } else {//else write error message, possibly wrong format.
					writeOut("ERROR: FreqIn = "+ freqIn + " <= FreqOut " + freqOut);
				 }// if freqIn > freqOut
			  }//if freqOut isLong
		   }//if freqIn isLong	  
		 }//if line long enough
	  }//while line

//	  return;
//   }//end readIn
///////////////////////////////////////////////////////////////////////////////

//efferent (outbound data)
//   static void writeResults(Freq freqs){
/** writeResults
*@param  ArrayList<Freq> 
*   writes $$$$$$$$$$... to mark the beginning of the pay dirt.
*   writes labels properly spaced for the data.
*   writes the results in a pleasing format.
*
*   note that the input data has been written, part of the documentation.
*
*@returns void
*/

///////////////////////////////////////////////////////////////////////////////
//Create table of easily changable labels (format automatically adjusts)
	  String labelFreqIn	   = "FreqIn"; 
	  String labelFreqOut	  = "FreqOut";
	  String labelDenominator  = "Denominator";
	  String labelNumerator	= "Numerator";
	  String labelDenomHex	 = "DenomHex(HEX)";
	  String labelRateBitsRev  = "RateBitsRev(HEX)";

	  int spaceBetweenLabels = 4; // minimum space between labels(adjust to taste).

// field size variable declaration and initialization.
	sizeFreqIn	 =Math.max(labelFreqIn.length(),	 sizeOfDec(	 freqInMax));
	sizeFreqOut	=Math.max(labelFreqOut.length(),	sizeOfDec(	freqOutMax))+  spaceBetweenLabels;
	sizeDenominator=Math.max(labelDenominator.length(),sizeOfDec(denominatorMax))+  spaceBetweenLabels;
	sizeNumerator  =Math.max(labelNumerator.length(),  sizeOfDec(  numeratorMax))+  spaceBetweenLabels;
	sizeDenomHex   =Math.max(labelDenomHex.length(),   sizeOfHex(denominatorMax-1))+spaceBetweenLabels;

	sizeRateBitsRev=Math.max(labelRateBitsRev.length(),sizeOfHex(rateBitsRevMax))+  spaceBetweenLabels;

	  writeOut(
"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
	  writeOut(" Minimum Counter size = "+ bitsInLong(denominatorMax-1) +" bits");
	  
	  //create a string with right justified labels
	  int lineLen = sizeFreqIn	  +	   
					  sizeFreqOut	 +
					  sizeDenominator +
					  sizeNumerator   +
					  sizeDenomHex	+
					  sizeRateBitsRev;

	  //Build header line
	  StringBuffer stringLine = new StringBuffer(lineLen);//allocation
	// blank entire line
	int ptr = lineLen;
	  while(0 < ptr) {
		ptr--;
		stringLine.append(" "); 
	  }

	  //insert label
	  ptr = sizeFreqIn - labelFreqIn.length();
	  stringLine.insert(ptr,labelFreqIn);

	  //insert label
	  ptr = sizeFreqIn + sizeFreqOut - labelFreqOut.length();
	  stringLine.insert(ptr,labelFreqOut);

	  //insert label
	  ptr = sizeFreqIn + sizeFreqOut + sizeDenominator - labelDenominator.length();
	  stringLine.insert(ptr,labelDenominator);

	  //insert label
	  ptr = sizeFreqIn + sizeFreqOut + sizeDenominator + sizeNumerator 
	  - labelNumerator.length();
	  stringLine.insert(ptr,labelNumerator);

	  //insert label
	  ptr = sizeFreqIn + sizeFreqOut + sizeDenominator + sizeNumerator 
	  + sizeDenomHex - labelDenomHex.length();
	  stringLine.insert(ptr,labelDenomHex);

	  //insert label
	  ptr = sizeFreqIn + sizeFreqOut + sizeDenominator + sizeNumerator 
	  + sizeDenomHex + sizeRateBitsRev - labelRateBitsRev.length();
	  stringLine.insert(ptr,labelRateBitsRev);
	  
	 //truncate stringLine
	  stringLine.setLength(lineLen);
	  
	  writeOut(""+stringLine);	//writeOut Header, "" is required.

	  // for each Freq object, output data
	  Iterator f = freqs.iterator();
	  while(f.hasNext()){ 
		 System.out.println( (Freq)f.next() );
	  }// for

   } // end main						  

}///:~

This post has been edited by Dark_Nexus: 21 October 2006 - 02:04 PM


Is This A Good Question/Topic? 0
  • +

Replies To: can not resolve symbol

#2 dragonlady  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 57
  • Joined: 07-August 05

Re: can not resolve symbol

Posted 21 October 2006 - 12:44 PM

You're having trouble with the line:
public long getFreqIn(){return freqIn;};


right?

If I had to guess, I'd say that freqIn as you've defined it is not in the scope of the function getFreqIn. Just looking over your code, it looks like freqIn is actually declared in the constructor for Freq class. Therefore, any reference to freqIn outside of the constructor will return an error. I'd start by declaring freqIn outside of the constructor, as a global variable. Then, any function that needs to access that variable can do so without an error.

Also, as a side note, the code was a bit hard to read. I think using some tabs and different spacing will really help you (and me, lol) keep better track of what's going on in your code. Just some friendly advice :)

Hope that helps.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1