5 Replies - 2406 Views - Last Post: 23 April 2010 - 05:23 PM Rate Topic: -----

#1 jsaurer   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 30-April 09

Cannot find symbol error

Posted 23 April 2010 - 01:22 PM

Here is my code.

package JessicaSaurerWeek3TreeLab;

* @author Home


import java.util.*;
import java.util.Iterator;

public class JessicaSaurerWeek3TreeLab implements Comparable<JessicaSaurerWeek3TreeLab>
    private char one_letter;

    public JessicaSaurerWeek3TreeLab (char oneletter)
		one_letter = oneletter;

    public int compareTo(JessicaSaurerWeek3TreeLab o)
		if (this == o) return 0;
		if (this.o < one_letter) return -1;

    public String toString()

    public static void main(String[]args){

	String fullname = " Jessica Saurer";
        System.out.println("My name is" + fullname);

	JessicaSaurerWeek3TreeLab oletter1 = new JessicaSaurerWeek3TreeLab("s");
        JessicaSaurerWeek3TreeLab oletter2 = new JessicaSaurerWeek3TreeLab("a");
        JessicaSaurerWeek3TreeLab oletter3 = new JessicaSaurerWeek3TreeLab("u");
        JessicaSaurerWeek3TreeLab oletter4 = new JessicaSaurerWeek3TreeLab("r");
        JessicaSaurerWeek3TreeLab oletter5 = new JessicaSaurerWeek3TreeLab("e");
        JessicaSaurerWeek3TreeLab oletter6 = new JessicaSaurerWeek3TreeLab("r");

        System.out.println(oletter1 + "" +oletter2);

        System.out.println("Contents of treeset");

        Iterator it1 = t1.iterator();

            Object o1 = it1.next();


Now I am getting two different cannot find symbol errors. The first one it in the compareTo section, on the line if (this.o < one_letter) return -1;. The error is for the "o". I don't understand this error since it excepted the "o" in the line right above it. The next cannot find symbol error is in the tree set section. It says cannot find symbol JessicaSaurerWeek3TreeLab. I think it is referring to the one next to new. Again I don't understand why. Can anyone explain this to me?

Is This A Good Question/Topic? 0
  • +

Replies To: Cannot find symbol error

#2 japanir   User is offline

  • jaVanir
  • member icon

Reputation: 1014
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

Re: Cannot find symbol error

Posted 23 April 2010 - 01:28 PM

this refers to this object.
o is not a member of JessicaSaurerWeek3TreeLab Object.
so you cannot refer o as

o is only a parameter you pass to the compareTo method.
perhaps you mean:
if(o.oneLetter < this.oneLetter)

as for the TreeSet problem, I see no TreeSet Object in your code.
what is t1? perhaps it is an Object you forgot to declare?
Was This Post Helpful? 0
  • +
  • -

#3 JoeJo   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 23-April 10

Re: Cannot find symbol error

Posted 23 April 2010 - 04:53 PM

Hi all I am new to this site and let me say it has been a help...a great help. I also want to say that JGrasp is a good compiler for beginners (like me) and I also want to say thank you to the creator of the tutorial at


below in my code I am getting the cannot find symbol error

import javax.swing.JFrame; 
import java.awt.event.*;
import java.awt.*;

public class MortgageCalculator extends JFrame
		//declare the width & height of the calculator
		private static final int Width = 300;
		private static final int Height = 300;
		//declare the labels for the calculators text fields
		private JLabel MAmount;
		private JLabel MRate;
		private JLabel MTime;
		private JLabel MPayment;
		//declare the text fields for the calculator
		private JTextField Loan;
		private JTextField Interest;
		private JTextField Term;
		private JTextField MonthlyP;
		//declare the calculator's button
		private JButton CalculateButt;
		private JButton ResetButt;
		private JButton ExitButt;
		public MortgageCalculator(){
		//create instanses of the text field's labels
		MAmount = new JLabel("Enter the Principle: ", SwingConstants.RIGHT);
            MRate = new JLabel("Enter the Rate: ", SwingConstants.RIGHT);
            MTime = new JLabel("Enter the Term: ", SwingConstants.RIGHT);
            MPayment = new JLabel("Monthly Payment: ", SwingConstants.RIGHT);
				//create instanses of the calculator's text fields
				Loan = new JTextField(5);
            Interest = new JTextField(5);
            Term = new JTextField(5);
            MonthlyP = new JTextField(5);
				//SPecify handlers for each button and add (register) ActionListeners to each button.
            CalculateButt = new JButton("Calculate");
            CalcB = new CalculateButtonHandler();
            ResetButt = new JButton("Reset");
            Refresh = new ResetButtonHandler();
				ExitButt = new JButton("Exit");
				CloseOut = new ExitButtonHandler();
				//create instances of the calculator's buttons
            CalculateButt = new JButton("Calculate");
            ResetButt = new JButton("Reset");
				ExitButt = JButton("Exit");	
				//sets the title of the frame
				setTitle("Change Request 5");
				//get the content pane
				Container pane = getContentPane();
				//set the layout
				pane.setLayout(new Gridlayout (4,2));
				//Add the labels and text fields to the pane in the order you want them to appear (left to right, top to bottom)
				//sets the dimensions of the window
				setSize(WIDTH, HEIGHT);
				//allows the user to see the window on screen
				//defines how the window will act when the "X" is pressed
private class CalculateButtonHandler implements ActionListener
              public void actionPerformed(ActionEvent e)
                       // declare new variables which will hold user input & calculated result 
								double P, R, T;
                        //tells the program which user input to pass to which of the declared variables
								//We use the getText & setText methods to manipulate the data entered into those fields
                        P = Double.parseDouble(Loan.getText()); 
                        R = Double.parseDouble(Interest.getText())/12;
                        T = Double.parseDouble(Term.getText())*12;
								//calculate the monthly payment
								MonthlyP = P*Math.pow(1+R,N)*R/(Math.pow(1+R,N)-1);
								MonthlyP.setText("" + MonthlyP);

private class ResetButtonHandler implements ActionListener
     		      public void actionPerformed(ActionEvent e)
public class ExitButtonHandler implements ActionListener
                public void actionPerformed(ActionEvent e)
        public static void main(String[] args)
                MortgageCalculator mortObj = new MortgageCalculator();

I thought i followed the tutorial carefully enough but it seems i am doing something different. :eek:

Thanks in advanced.
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101   User is online

  • Games, Graphs, and Auctions
  • member icon

Reputation: 12305
  • View blog
  • Posts: 45,401
  • Joined: 27-December 08

Re: Cannot find symbol error

Posted 23 April 2010 - 05:07 PM

You only imported import javax.swing.JFrame;; however, many other GUI components like JLabel are also in the javax.swing package. To be safe, you may want to import import javax.swing.*; to take care of everything.

Also, in the future, feel free to open up a new thread for your topic rather than continuing on someone else's. That way, it gets the attention you need. :)
Was This Post Helpful? 0
  • +
  • -

#5 nighttmmare   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 23-April 10

Re: Cannot find symbol error

Posted 23 April 2010 - 05:17 PM

Hi jessica, i looked your code and you used iterator but There is nothing for using it.
May be you wanted to create an JessicaSaurerWeek3TreeLab array and to use iterator on traverseling.
First declare an arrray of JessicaSaurerWeek3TreeLab
Then add all JessicaSaurerWeek3TreeLab nodes to array( oletter1 , oletter2 ... )
after all your code make sense :)
i hope this helps you.
Was This Post Helpful? 0
  • +
  • -

#6 zim1985   User is offline

  • Grand Inquisitor
  • member icon

Reputation: 75
  • View blog
  • Posts: 568
  • Joined: 19-February 10

Re: Cannot find symbol error

Posted 23 April 2010 - 05:23 PM

This question was answered, though I would like to point out one thing. In the beginning you have your imports:
import java.util.*:
import java.util.Iterator;

The second import is unnecessary because you did a wildcard import first (which gets all classes in the java.util package). In other words, your first import is already importing iterator.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1