2 Replies - 1587 Views - Last Post: 05 August 2006 - 04:11 PM Rate Topic: -----

#1 plfarquhar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 05-August 06

Can Not Resolve Symbol Error

Posted 05 August 2006 - 03:36 PM

I am learining Java and I have two books on java, but I am having problems with my Combo box. I know that Can not resolve symbol error usually means that a variable is not initlized, but this is supposed to be for the combo box so I do not know what is wrong. If any one could help me it would be greatly appreciated. See code below:

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat:
import javax.swing.JOptionPane;
import javax.swing.*;
import javax.swing.event.*;

public class paulfarquhar extends Applet implements ActionListener

{
	 double loan, interest, term, mpayment;
	 String list;
	 DecimalFormat df = new DeciamlFormat ("$#,#0.00);

	 Label loanLabel = new Label("Enter the amount of your	  loan: ";

	 TextField loanField = new TextField(10);
	 Button calcButton = new Button("Calculate");
	Label outputLabel = new Label ("Click the Calculate button   to see what your monthly payment will be.");
	 public void init()
	 {
		  add (loanLabel);
		  add (loanField);
		  JComboBox list = new JComboBox();
		  FlowLayout flo = new FlowLayout();
		 list.addItem("7 Years at 5.35%");
		 list.addItem("15 Years at 5.5%");
		 list.addItem("30 Years at 5.75%");
		 setLayout(flo);
		 add(list);
		 add(calcButton);
		 calcButton.setActionCommand("caculate");
		 calcButton.addActionListener(this);
		 add(outputLabel);
		 add(clearButton);
		 clearButton.setActionCommand("clear");
		 clearButton.addActionListener(this);
	 }
	 public void actionPerformed (ActionEvent e)
	 {
		  String arg = e.getActionCommand();
		  {
			   if (arg == "caculate")
			   {
					if (e.getSource() == list)
					{
						 String s = (String)list.getSelectedItem();
							  if (s.equals("7 Years at 5.35%));
								   term = (7);
								   interest = (.0535);
							  if(s.equals("15 Years at 5.5%));
								   term = (15);
								   interest = (.0550)
							  if(s.equals("30 Years at 5.75%"));
								   term = (30)
								   interest = (.0575);
					  }
				  }
			  }
		   }
}




The error I get is with the line right above my if statements pointing at the period right before getSelectedItem. The full error I get is: cannot resolve symbol
symbol : method getSelectedItem ()
location: class java.lang.String

Any help would be greatly appreciated.

Thank you.

Is This A Good Question/Topic? 0
  • +

Replies To: Can Not Resolve Symbol Error

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Can Not Resolve Symbol Error

Posted 05 August 2006 - 04:01 PM

There isn't any String method called getSelectedItem(). Here is the API for String class.

Which class are you using that method from?
Was This Post Helpful? 0
  • +
  • -

#3 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Can Not Resolve Symbol Error

Posted 05 August 2006 - 04:11 PM

Oh, I see what you are doing. You are trying to get the selected item in the Combobox. Problem is the scope of your Combobox is limited to your init() method. So what is happening is that the String list that you declared at the class level is the object that method is trying to access, not the Combobox as you are wanting.

You need to declare the Combobox at the class level, which will bring you to your next problem. You will have 2 objects named list. So one of them needs to be named something different.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1