Cannot find symbol

I must be missing something

Page 1 of 1

12 Replies - 774 Views - Last Post: 11 April 2010 - 08:41 AM Rate Topic: -----

#1 MKunstman  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 190
  • Joined: 26-October 09

Cannot find symbol

Posted 09 April 2010 - 04:28 PM

Ok, so have the program all but finished. I am getting errors on lines 55 and 57 that say:
cannot find symbol
symbol : class InvalidColorException
location: class unit7project.JColorChange
else throw new InvalidColorException(answer);
symbol : class InvalidColorException
location: class unit7project.JColorChange
catch (InvalidColorException error){
2 errors

Now this code is similar to examples in my book and provided by the instructor. In fact at this point in an effort to at least get it running I am using a replica of one example to see if it could show me what I was doing wrong...and I am here so it did not help...haha.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
 
 */
public class JColorChange extends JApplet implements ActionListener{
    //declare necessary labels
    JLabel header = new JLabel("Please enter your color choice.");
    JLabel errortxt = new JLabel("");
    //declare necessary textfield and button
    JTextField userInput = new JTextField(20);
    JButton select = new JButton("Select");
    //declare necessary strings
    String answer;
    String redString = "red";
    String whiteString = "white";
    String blueString = "blue";
    //create container
    Container con = getContentPane();

    public void init() {
        //populate container
        con.add(header);
        con.add(userInput);
        con.add(select);
        con.add(errortxt);
        //set container layout
        con.setLayout(new FlowLayout());
        //add action listener to button
        select.addActionListener(this);
    }

    public void actionPerformed(ActionEvent e){
        //get user input from text field
        answer = userInput.getText();
        //try block to ensure data is valid or throw exception
        try{
            errortxt.setText("");

            if(redString.equalsIgnoreCase(answer)){
                getContentPane().setBackground(Color.RED);
            }
            else if(blueString.equalsIgnoreCase(answer)){
                getContentPane().setBackground(Color.BLUE);
            }
            else if(whiteString.equalsIgnoreCase(answer)){
                getContentPane().setBackground(Color.WHITE);
            }
            else throw InvalidColorException(answer);
        }
        catch (InvalidColorException error){
            errortxt.setText("No color available");
            getContentPane().add(errortxt);
        }
    }
}


Any help would be appreciated

Is This A Good Question/Topic? 0
  • +

Replies To: Cannot find symbol

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 9037
  • View blog
  • Posts: 33,521
  • Joined: 27-December 08

Re: Cannot find symbol

Posted 09 April 2010 - 04:35 PM

It looks like InvalidColorException is a part of an API provided to you by your instructor. Make sure you import it from the cs2110.assignment3 package.

Here is the link to the API for this class: http://www.cs.cornel...rException.html
Was This Post Helpful? 1
  • +
  • -

#3 MKunstman  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 190
  • Joined: 26-October 09

Re: Cannot find symbol

Posted 09 April 2010 - 04:40 PM

Sorry the original code he used for an example was written
	else throw new ColorException(answer);
			//If input does not equal any of the above throw an error message
		}		
catch (ColorException error)
		{
		   //Set errorMessage label
			errorMessage.setText("No such color available");
			//Add to screen
			getContentPane().add(errorMessage);
		}


I was the one that made it InvalidColorException...I forgot I did change that to see if it changed things

This post has been edited by MKunstman: 09 April 2010 - 04:42 PM

Was This Post Helpful? 0
  • +
  • -

#4 MKunstman  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 190
  • Joined: 26-October 09

Re: Cannot find symbol

Posted 10 April 2010 - 05:09 AM

View PostMKunstman, on 09 April 2010 - 03:40 PM, said:

Sorry the original code he used for an example was written
	else throw new ColorException(answer);
			//If input does not equal any of the above throw an error message
		}		
catch (ColorException error)
		{
		   //Set errorMessage label
			errorMessage.setText("No such color available");
			//Add to screen
			getContentPane().add(errorMessage);
		}


I was the one that made it InvalidColorException...I forgot I did change that to see if it changed things


Still no luck awaiting my prof to hopefully answer the question I have posed here
Was This Post Helpful? 0
  • +
  • -

#5 Dogstopper  Icon User is online

  • The Ninjaducky
  • member icon



Reputation: 2695
  • View blog
  • Posts: 10,556
  • Joined: 15-July 08

Re: Cannot find symbol

Posted 10 April 2010 - 06:45 AM

In order to use ColorExceptions, you have to import it from the library that your professor gave you as macosxnerd101 stated.
Was This Post Helpful? 1
  • +
  • -

#6 MKunstman  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 190
  • Joined: 26-October 09

Re: Cannot find symbol

Posted 10 April 2010 - 10:30 AM

the example the prof gave me only has this for imports

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


So I assumed it was something that could be created within the code as it is written in my program.

I guess it is not that I do not understand what you guys are saying...but I am just beginning covering exceptions and error handling and we have not really talked about exception libraries...just the basics of creating them for user assistance as well as a half cocked way to create your own, which I would do, but as the description points out, it failed.

This post has been edited by MKunstman: 10 April 2010 - 11:19 AM

Was This Post Helpful? 0
  • +
  • -

#7 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 9037
  • View blog
  • Posts: 33,521
  • Joined: 27-December 08

Re: Cannot find symbol

Posted 10 April 2010 - 11:33 AM

Your professor's example was probably stored in the same package as the ColorExceptions. I looked in the AWT and AWT Color packages, but there was no mention of any ColorExceptions. They are stored in the package provided to you by your instructor, so you have to import from that package.
Was This Post Helpful? 1
  • +
  • -

#8 MKunstman  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 190
  • Joined: 26-October 09

Re: Cannot find symbol

Posted 10 April 2010 - 11:40 AM

View Postmacosxnerd101, on 10 April 2010 - 10:33 AM, said:

Your professor's example was probably stored in the same package as the ColorExceptions. I looked in the AWT and AWT Color packages, but there was no mention of any ColorExceptions. They are stored in the package provided to you by your instructor, so you have to import from that package.

What package? Nothing is provided just working in NetBeans...and reading the book. Sorry for sounding like a noob there but I have nothing from my professor but that one example..
Was This Post Helpful? 0
  • +
  • -

#9 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 9037
  • View blog
  • Posts: 33,521
  • Joined: 27-December 08

Re: Cannot find symbol

Posted 10 April 2010 - 11:47 AM

These Exceptions your instructor is using do not come with the standard Java library. So if you do not have the package your instructor is using, then you cannot run the program unless you rewrite these Exceptions.
Was This Post Helpful? 1
  • +
  • -

#10 MKunstman  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 190
  • Joined: 26-October 09

Re: Cannot find symbol

Posted 10 April 2010 - 11:51 AM

View Postmacosxnerd101, on 10 April 2010 - 10:47 AM, said:

These Exceptions your instructor is using do not come with the standard Java library. So if you do not have the package your instructor is using, then you cannot run the program unless you rewrite these Exceptions.

I guess that is where I get stuck. Do I create a separate class for the exception and then make it throwable....is there a better way to do it? I guess I am missing something because it makes no mention of that in the book and their examples work fine...though none of them apply to a if...else structure so I am not sure how to adapt them unless I were to make 3 try statements which is structurally wrong to do
Was This Post Helpful? 0
  • +
  • -

#11 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 9037
  • View blog
  • Posts: 33,521
  • Joined: 27-December 08

Re: Cannot find symbol

Posted 10 April 2010 - 12:00 PM

If you want to re-write these Exceptions, you should extend Exception, not Throwable.

Quote

I guess I am missing something

This is what we have been saying. Talk to your instructor about getting this missing package. I'm guessing that since you are copying and running an example, your instructor has not asked you to do this, so I bet if you wait it out, you will get a copy of this package within the next couple of classes.
Was This Post Helpful? 1
  • +
  • -

#12 MKunstman  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 190
  • Joined: 26-October 09

Re: Cannot find symbol

Posted 11 April 2010 - 07:04 AM

I wanted to thank you guys again for your help...I cannot say how nice it is to have people here willing to look over my work and assist with issues. I currently have the applet running with the color problem as an IOException (which I know is not the best route) and I hope to learn more about the package the Prof was using later.

Again thank you all I appreciate it each and every time!
Was This Post Helpful? 0
  • +
  • -

#13 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 9037
  • View blog
  • Posts: 33,521
  • Joined: 27-December 08

Re: Cannot find symbol

Posted 11 April 2010 - 08:41 AM

Not a problem! We're glad we could help! :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1