wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes cannot resolve symbol Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "cannot resolve symbol" Watch "cannot resolve symbol" New topic
Author

cannot resolve symbol

Jen Wren
Greenhorn

Joined: Nov 22, 2004
Posts: 17
I am getting this erro when I compile my code. I have worked out all the other bugs and now understand where they came from, but this one is a little baffeling to me. I have not changed any of the code in the area of the line that is giving me the problem (JComboBox interest = new JComboBox(interestArray) . Any ideas?


cannot resolve symbol
symbol: constructor JComboBox (java.lang.String)

import javax.swing.*; //importing the ability to create and use a frame
import java.awt.*; //importing the swing functions like the combo box
import java.awt.event.*;
import java.lang.String;
import java.io.*;
import java.math.*;

public class MortgageFrame5 extends JFrame implements ItemListener, ActionListener, Runnable{

//setting up my variables
String paythis;
double monthly;
int a;
int t;
double I;
double total;
int loop;
double balance;
String actInt;

int totalGraph;
int interestGraph;
int principalGraph;
int pie[];
int pieDegree[];

//creating lables, boxes, arrays, and buttons
JLabel amountLabel = new JLabel ("House cost in dollars:");
JComboBox amount = new JComboBox();{
amount.addItem("$100,000");
amount.addItem("$125,000");
amount.addItem("$150,000");
amount.addItem("$175,000");
amount.addItem("$200,000");
amount.addItem("$225,000");
amount.addItem("$250,000");
amount.addItem("$275,000");
}
JLabel tILabel = new JLabel ("Payment term and rate:");
String[] termsInterestArray = {"7 years at 5.35%", "15 years at 5.5%", "30 years at 5.75%"};
String[] termsArray = {"7 years", "15 years", "30 years"};
String interestArray = readData();

private String readData(){
String s = null;
try{
File interestRate = new File("interestRate.txt");
FileInputStream fileStream = new FileInputStream(interestRate);
BufferedReader stream = new BufferedReader(new InputStreamReader(fileStream));
s = new String(stream.readLine());
}
catch (Exception e){
System.err.println("Could not read file.");
}
return s;
}

JComboBox tI = new JComboBox(termsInterestArray);
JComboBox term = new JComboBox(termsArray);
JComboBox interest = new JComboBox(interestArray);
JButton calculate = new JButton("Calculate");
JButton quit = new JButton("Quit");
JLabel heading = new JLabel ("Payment | Loan Balance | Interest Paid");
JTextArea future = new JTextArea (180, 40);
JScrollPane futureInfo = new JScrollPane(future);

JCheckBox seperateCheck = new JCheckBox("Check to select term and interest seperately");
JCheckBox tICheck = new JCheckBox("Check to select term and interest together");
ButtonGroup select = new ButtonGroup();

public MortgageFrame5(){
//setting up the frame and frame characteristics
setTitle("Mortgage calculator");
setSize(340,350);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true); //user can see the box
FlowLayout flo = new FlowLayout();
Container pane = getContentPane();
future.setLineWrap(true);
select.add(seperateCheck);
select.add(tICheck);

//setting the default layout manager and adding everything to the container
pane.setLayout(flo);
pane.add(amountLabel);
pane.add(amount);
pane.add(tILabel);
pane.add(tICheck);
pane.add(tI);
pane.add(seperateCheck);
pane.add(term);
pane.add(interest);
pane.add(calculate);
pane.add(quit);
pane.add(heading);
pane.add(futureInfo);
setContentPane(pane);

//setting up the listeners
amount.addItemListener(this);
tI.addItemListener(this);
term.addItemListener(this);
interest.addItemListener(this);
seperateCheck.addItemListener(this);
tICheck.addItemListener(this);
calculate.addActionListener(this);
quit.addActionListener(this);
repaint();
// retrieving the interest rates from the file
}

//this is where the program will act upon the user selections
public void itemStateChanged(java.awt.event.ItemEvent e){

}
//This is where the calculate button functionality comes from
public void actionPerformed(ActionEvent event){
if(event.getSource() == calculate){
String strA = (String)amount.getSelectedItem();
if (strA.equals("$100,000")){
a = 100000;
}
else if (strA.equals("$125,000")){
a = 125000;
}
else if (strA.equals("$150,000")){
a = 150000;
}
else if (strA.equals("$175,000")){
a = 175000;
}
else if (strA.equals("$200,000")){
a = 200000;
}
else if (strA.equals("$225,000")){
a = 225000;
}
else if (strA.equals("$250,000")){
a = 250000;
}
else if (strA.equals("$275,000")){
a = 275000;
}
if (seperateCheck.isSelected()){
String strT = (String)term.getSelectedItem();
if (strT.equals("7 years")){
t = 7*12;
}
else if (strT.equals("15 years")){
t = 15*12;
}
else if (strT.equals("30 years")){
t = 30*12;
}
String strI = (String)interest.getSelectedItem();
if (strI.equals("5.35%")){
I = 0.0535;
}
else if (strI.equals("5.5%")){
I = 0.055;
}
else if (strI.equals("5.75%")){
I = 0.0575;
}
}
else if (tICheck.isSelected()){
String strT = (String)tI.getSelectedItem();
if (strT.equals("7 years at 5.35%")){
t = 7*12;
I = 5.35;
}
else if (strT.equals("15 years at 5.5%")){
t = 15*12;
I = 5.5;
}
else if (strT.equals("30 years at 5.75%")){
t = 30*12;
I = 5.75;
}
}

}
total = ((I/1200) + (I/1200)/(Math.pow(1+(I/1200),t) -1)) * 100 * a;
monthly = total/t;
balance = total;
actInt = ("$" + (Math.round((monthly * I)* 100) / 100.00));

//setting up the loop to run and print the information into the text area
future.setText("\n");
for (int loop = 1; loop <= t; loop ++){
monthly = Math.round(monthly * 100) / 100;
balance = Math.round(balance * 100) / 100;
future.append("\t $" + monthly + "\t $" + balance + "\t" + actInt + "\n");
balance = (total - (monthly*loop));
}
interestGraph = (int)(total * I) / 100;
principalGraph = (int)(total);
pie = new int[2];
pieDegree = new int [2];
pie[0] = interestGraph;
pie[1] = principalGraph;
totalGraph = pie[0] + pie[1];
pieDegree[0] = ((pie[0] * 360) / totalGraph);
pieDegree[1] = ((pie[1] * 360) / totalGraph);

if(event.getSource() == quit){
System.exit(0);
}
}

public void paint (Graphics graph){
super.paint(graph);
graph.setColor(Color.red);
graph.fillArc(100, 100, 100, 100, 0, pieDegree[0]);
graph.setColor(Color.black);
graph.fillArc(100, 100, 100, 100, pieDegree[1], pieDegree[0]);
}

public void run(){
}
//this is the main function where the program runs
public static void main(String[] arguments){
MortgageFrame5 mor = new MortgageFrame5();
}
}
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Despite the name, interestArray is a String, not an array. There's no JComboBox constructor that takes a single String as an argument -- that's the unresolved symbol.


[Jess in Action][AskingGoodQuestions]
Jen Wren
Greenhorn

Joined: Nov 22, 2004
Posts: 17
I see what you are saying. It used to be an array, but I removed the [] and the items that were in the array when I changed it to read from the sequential file. I tried to leave it as an array, but was getting errors that way and by process of elimination and removal I have gotten to where I am now. It sounds like I have been removing the wrong things though. Is there a way that I can have the fileReader retrieve the information from the file and make it an array? And will that solve my problem?
Thanks
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: cannot resolve symbol
 
Similar Threads
last week of class last assignment. Any help is appreciated.
Interesting exception errors
Help with errors again
illegal start of type error
JButton not working