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

#1 jsaurer  Icon 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;
	}

    @Override
    public String toString()
	{
		return""+one_letter;
	}


    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();

        while(it1.hasNext()){
            Object o1 = it1.next();
            System.out.println(o1);

    }
    }
}





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  Icon User is offline

  • jaVanir
  • member icon

Reputation: 1010
  • 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
this.o

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  Icon 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

http://www.dreaminco...c-gui-concepts/

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();
            CalculateButt.addActionListener(CalcB);
            ResetButt = new JButton("Reset");
            Refresh = new ResetButtonHandler();
            ResetButt.addActionListener(Refresh);
				ExitButt = new JButton("Exit");
				CloseOut = new ExitButtonHandler();
				ExitButt.addActionListener(CloseOut);
				//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)
            pane.add(MPrinciple);
            pane.add(MRate);
            pane.add(MTime);
            pane.add(MPayment);
            pane.add(Loan);
            pane.add(Interest);
            pane.add(Term);
            pane.add(MonthlyP);
				pand.add(CalculateButt);
				pane.add(ResetButt);
				pane.add(ExitButt);
				//sets the dimensions of the window
				setSize(WIDTH, HEIGHT);
				//allows the user to see the window on screen
				setVisible("true");
				//defines how the window will act when the "X" is pressed
				setDefaultCloseOperation(EXIT_ON_CLOSE);
				}
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)
					{
						Loan.setText("");
						Rate.setText("");
						Term.setText("");
						MonthlyP.setText("");
			      }
}
public class ExitButtonHandler implements ActionListener
        {
                public void actionPerformed(ActionEvent e)
                {
                        System.exit(0);
                }
        }
        
        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  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10470
  • View blog
  • Posts: 38,809
  • 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  Icon 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  Icon User is offline

  • Grand Inquisitor
  • member icon

Reputation: 74
  • 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