Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Cannot Resolve Symbol Error

  1. #1
    Member tyeeeee1's Avatar
    Join Date
    Sep 2012
    Posts
    61
    Thanks
    31
    Thanked 2 Times in 2 Posts

    Default Cannot Resolve Symbol Error

    Hey, I'm currently messing around with a little side-project and I just ran into an error that I've seen and fixed myself a few times but for some reason the fixes I've used in the past aren't working. (Most of the time I just had to make sure I spelled the variable names correctly.)

    If anyone has a sec to check out the problem lines they are on lines 129 and 185. I've double checked that the spelling is correct on both of the lines so I'm not sure what could be causing this error.

    import java.io.*;
    import javax.swing.*; //Needed for the swing class
    import java.awt.*;
    import java.awt.event.*; //Needed for action event listeners for the buttons
    import java.awt.image.*;
     
    class SavingClass
    {
    	public static void saveGame() throws Exception //Change the return type (void) to something else later.
    	{
    		BufferedWriter saveFile = new BufferedWriter(new FileWriter("TextSave.txt")); 
     
    		saveFile.write("test1, test2"); //Saves the variables listed to the first line of the CSV file. If you wanted to make another line then you would end this one with \r\n so that a new line is created. Then you would make another write method
     
    		saveFile.close(); //Closes the file writer now that we're finished.
    	}
    }
     
    class LoadingClass
    {
    	public static void loadGame() throws Exception //Change the return type (void) to something else later.
    	{
    		String exampleString1;
    		String exampleString2;
     
    		BufferedReader saveFile = new BufferedReader(new FileReader("TextSave.txt"));
     
    		exampleString1 = saveFile.readLine();
    		exampleString2 = saveFile.readLine();
     
    		saveFile.close();
     
    		System.out.println(""+exampleString1+" "+exampleString2+"");
    	}
    }
     
    class CreateGameWindowFirst extends JFrame
    {
    	//The below method is used for the creation of the game window.
    	public CreateGameWindowFirst() //If there is a return type set for this method then the code below will not show.
    	{
    		setSize(640, 480); //Sets the size of the game window
    		setLocationRelativeTo(null); //Centers the window on the users screen.
    		setTitle("The Game - By Tyler MacEachern"); //Sets the title of the game window
    		setDefaultCloseOperation(EXIT_ON_CLOSE); //Basically this makes it so when you hit the red X the window and program will close.
    		setResizable(false); //Makes it so that the user cannot resize the JFrame.
     
    		final JPanel gamePanel = new JPanel(); //Creates a new JPanel to put everything on.
    		getContentPane().add(gamePanel);
     
    		gamePanel.setLayout(null); //Makes it so you can manually positon everything using XY coords.
     
    		CreateMainMenu gameWindow = new CreateMainMenu(gamePanel); //Tells the program to run the CreateMainMenu class so that the main menu will be created.
     
    		setVisible(true); //Makes the JFrame, also known ass gameWindow visible to the user.
    	}
    }
     
    class CreateMainMenu extends JFrame
    {
    	public CreateMainMenu(final JPanel gamePanel)
    	{
    		//Create the main menu's look with buttons and that
    		Insets insets = gamePanel.getInsets(); //Gets the amount of space that the gameWindow's boarders take up so that you can use it to better position your JButtons and stuff.
     
    		final JButton newGameButton = new JButton(""); //Creates a button object for the New Game button on the main menu.
    		final JButton loadGameButton = new JButton(""); //Creates a button object for the Load Game button on the main menu.
    		final JButton optionsButton = new JButton(""); //Creates a button object for the Options button on the main menu.
     
    		gamePanel.add(newGameButton); //Adds the New Game button to the JPanel
    		newGameButton.setBounds(200 + insets.left, 140 + insets.top, 180, 40);
    		newGameButton.setBorder(null); //Disables the thin black box around the button
    		newGameButton.setFocusPainted(false); //Makes it so that when you select the button there wont be a little box around the words to signify that the button is currently selected.
    		newGameButton.setContentAreaFilled(false); //Gets rid of the grey fill when you select the button.
    		Icon newGameButtonIcon = new ImageIcon("button_newGame_normal.png"); //Creates a new ImageIcon object that will be used as the newGameButton.
    		newGameButton.setIcon(newGameButtonIcon); //Covers the newGameButton icon with the testbutton.png image.
    		Icon newGameButtonIconRollover = new ImageIcon("button_newGame_rollover.png"); //Creates a new ImageIcon object that will be used as the rollover version of the newGameButton.
    		newGameButton.setRolloverIcon(newGameButtonIconRollover); //Tells the newGameButton to, when the mouse is over it, change to the rollover version of the newGamebutton.
    		Icon newGameButtonIconPressed = new ImageIcon("button_newGame_press.png");
    		newGameButton.setPressedIcon(newGameButtonIconPressed);
    		newGameButton.addActionListener(new ActionListener() {  //Action listener for the newGameButton
    			public void actionPerformed(ActionEvent e) {
    				System.out.println("You've pressed the New Game Button on the main menu screen.");
    				gamePanel.remove(newGameButton); //Removes the newGameButton
    				gamePanel.remove(loadGameButton); //Removes the loadGamebutton
    				gamePanel.remove(optionsButton); //Removes the optionsButton
    				gamePanel.repaint(); //Re-loads the JPanel, also known as gamePanel, so that the deleted buttons disappear.
    			}});
    		//
    		gamePanel.add(loadGameButton); //Adds the Load Game button to the JPanel
    		loadGameButton.setBounds(200 + insets.left, 210 + insets.top, 180, 40);
    		loadGameButton.setBorder(null); //Disables the thin black box around the button
    		loadGameButton.setFocusPainted(false); //Makes it so that when you select the button there wont be a little box around the words to signify that the button is currently selected.
    		loadGameButton.setContentAreaFilled(false); //Gets rid of the grey fill when you select the button.
    		Icon loadGameButtonIcon = new ImageIcon("button_loadGame_normal.png"); //Creates a new ImageIcon object that will be used as the newGameButton.
    		loadGameButton.setIcon(loadGameButtonIcon); //Covers the newGameButton icon with the testbutton.png image.
    		Icon loadGameButtonIconRollover = new ImageIcon("button_loadGame_rollover.png"); //Creates a new ImageIcon object that will be used as the rollover version of the newGameButton.
    		loadGameButton.setRolloverIcon(loadGameButtonIconRollover); //Tells the newGameButton to, when the mouse is over it, change to the rollover version of the newGamebutton.
    		Icon loadGameButtonIconPressed = new ImageIcon("button_loadGame_press.png");
    		loadGameButton.setPressedIcon(loadGameButtonIconPressed);
    		loadGameButton.addActionListener(new ActionListener() {  //Action listener for the loadGameButton
    			public void actionPerformed(ActionEvent e) {
    				System.out.println("You've pressed the Load Game Button on the main menu screen.");
    				gamePanel.remove(newGameButton); //Removes the newGameButton
    				gamePanel.remove(loadGameButton); //Removes the loadGamebutton
    				gamePanel.remove(optionsButton); //Removes the optionsButton
    				gamePanel.repaint(); //Re-loads the JPanel, also known as gamePanel, so that the deleted buttons disappear.
    				CreateLoadGameMenu gameWindow = new CreateLoadGameMenu(gamePanel); //Passes the gamePanel object to the LoadGameMenu class so that it can be used there
    			}});
    		//
    		gamePanel.add(optionsButton); //Adds the Options Game button to the JPanel
    		optionsButton.setBounds(200 + insets.left, 280 + insets.top, 180, 40);
    		optionsButton.setBorder(null); //Disables the thin black box around the button
    		optionsButton.setFocusPainted(false); //Makes it so that when you select the button there wont be a little box around the words to signify that the button is currently selected.
    		optionsButton.setContentAreaFilled(false); //Gets rid of the grey fill when you select the button.
    		Icon optionsButtonIcon = new ImageIcon("button_optionsButton_normal.png"); //Creates a new ImageIcon object that will be used as the newGameButton.
    		optionsButton.setIcon(optionsButtonIcon); //Covers the newGameButton icon with the testbutton.png image.
    		Icon optionsButtonIconRollover = new ImageIcon("button_optionsButton_rollover.png"); //Creates a new ImageIcon object that will be used as the rollover version of the newGameButton.
    		optionsButton.setRolloverIcon(optionsButtonIconRollover); //Tells the newGameButton to, when the mouse is over it, change to the rollover version of the newGamebutton.
    		Icon optionsButtonIconPressed = new ImageIcon("button_optionsButton_press.png");
    		optionsButton.setPressedIcon(optionsButtonIconPressed);
    		optionsButton.addActionListener(new ActionListener() {  //Action listener for the newGameButton
    			public void actionPerformed(ActionEvent e) {
    				System.out.println("You've pressed the Options Button on the main menu screen.");
    				gamePanel.remove(newGameButton); //Removes the newGameButton
    				gamePanel.remove(loadGameButton); //Removes the loadGamebutton
    				gamePanel.remove(optionsButton); //Removes the optionsButton
    				gamePanel.repaint(); //Re-loads the JPanel, also known as gamePanel, so that the deleted buttons disappear.
    				CreateOptionsMenu gameWindow = new CreateOptionsMenu(gamePanel);
    			}});
    	}
    }
     
    class CreateLoadGameMenu extends JFrame
    {
    	public CreateLoadGameMenu(final JPanel gamePanel)
    	{
    		Insets insets = gamePanel.getInsets(); //Gets the amount of space that the gameWindow's boarders take up so that you can use it to better position your JButtons and stuff.
     
    		final JButton backButton = new JButton(""); //Creates a button object for the Back button on the main menu.
    		gamePanel.add(backButton); //Adds the Back button to the JPanel
    		backButton.setBounds(0 + insets.left, 400 + insets.top, 180, 40);
    		backButton.setBorder(null); //Disables the thin black box around the button
    		backButton.setFocusPainted(false); //Makes it so that when you select the button there wont be a little box around the words to signify that the button is currently selected.
    		backButton.setContentAreaFilled(false); //Gets rid of the grey fill when you select the button.
    		Icon backButtonIcon = new ImageIcon("button_backButton_normal.png"); //Creates a new ImageIcon object that will be used as the backButton.
    		backButton.setIcon(backButtonIcon); //Covers the backButton icon with the testbutton.png image.
    		Icon backButtonIconRollover = new ImageIcon("button_backButton_rollover.png"); //Creates a new ImageIcon object that will be used as the rollover version of the backButton.
    		backButton.setRolloverIcon(backButtonIconRollover); //Tells the backButton to, when the mouse is over it, change to the rollover version of the backButton.
    		Icon backButtonIconPressed = new ImageIcon("button_backButton_press.png");
    		backButton.setPressedIcon(backButtonIconPressed);
    		backButton.addActionListener(new ActionListener() {  //Action listener for the newGameButton
    			public void actionPerformed(ActionEvent e) {
    				System.out.println("You've pressed the Back Button on the Load Game screen.");
    				gamePanel.remove(backButton);
    				gamePanel.repaint(); //Re-loads the JPanel, also known as gamePanel, so that the deleted buttons disappear.
    				CreateMainMenu gameWindow = new CreateMainMenu(gamePanel);
    			}});
    	}
    }
     
    class CreateOptionsMenu extends JFrame
    {
    	public CreateOptionsMenu(final JFrame gamePanel)
    	{
    		Insets insets = gamePanel.getInsets(); //Gets the amount of space that the gameWindow's boarders take up so that you can use it to better position your JButtons and stuff.
     
    		final JButton backButton = new JButton(""); //Creates a button object for the Back button on the main menu.
    		gamePanel.add(backButton); //Adds the Back button to the JPanel
    		backButton.setBounds(0 + insets.left, 400 + insets.top, 180, 40);
    		backButton.setBorder(null); //Disables the thin black box around the button
    		backButton.setFocusPainted(false); //Makes it so that when you select the button there wont be a little box around the words to signify that the button is currently selected.
    		backButton.setContentAreaFilled(false); //Gets rid of the grey fill when you select the button.
    		Icon backButtonIcon = new ImageIcon("button_backButton_normal.png"); //Creates a new ImageIcon object that will be used as the backButton.
    		backButton.setIcon(backButtonIcon); //Covers the backButton icon with the testbutton.png image.
    		Icon backButtonIconRollover = new ImageIcon("button_backButton_rollover.png"); //Creates a new ImageIcon object that will be used as the rollover version of the backButton.
    		backButton.setRolloverIcon(backButtonIconRollover); //Tells the backButton to, when the mouse is over it, change to the rollover version of the backButton.
    		Icon backButtonIconPressed = new ImageIcon("button_backButton_press.png");
    		backButton.setPressedIcon(backButtonIconPressed);
    		backButton.addActionListener(new ActionListener() {  //Action listener for the newGameButton
    			public void actionPerformed(ActionEvent e) {
    				System.out.println("You've pressed the Back Button on the Options Menu screen.");
    				gamePanel.remove(backButton);
    				gamePanel.repaint(); //Re-loads the JPanel, also known as gamePanel, so that the deleted buttons disappear.
    				CreateMainMenu gameWindow = new CreateMainMenu(gamePanel);
    			}});
    	}
    }
     
    public class Game extends JFrame
    {	
    	public static void main(String args[]) //This is the main menu of the game, the method has been called 'main' so it will be the first thing to run when the program is loaded.
    	{
    		CreateGameWindowFirst gameWindow = new CreateGameWindowFirst(); //Calls the CreateGameWindow method of the CreateGameWindow class so that the window and that will be set up
    	}
    }

    PS: If the code above isn't displayed with the line numbers you can find the lines on the last line of the button action listeners of the CreateOptionsMenu and CreateLoadGameMenu methods in their respective classes.


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Cannot Resolve Symbol Error

    Please show the full text of any errors that you are seeing.

  3. #3
    Member tyeeeee1's Avatar
    Join Date
    Sep 2012
    Posts
    61
    Thanks
    31
    Thanked 2 Times in 2 Posts

    Default Re: Cannot Resolve Symbol Error

    The full error text is:



    From what I've read this error usually comes up when you misspell something, but as far as I can tell it looks correct. =/

  4. #4
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Cannot Resolve Symbol Error

    OK, the error message is telling you exactly what is wrong. You are trying to call the CreateMainMenu constructor and are passing a JFrame into this constructor. The compiler is saying that it can't find such a constructor. So you will need to check your code to see if such a constructor is present. You have a similar error for the other constructor (though not exactly the same). These should be easy to fix once you look carefully at your code. The key though is to try to glean as much from the error message as possible since it usually tells you all you need to know.

  5. The Following User Says Thank You to curmudgeon For This Useful Post:

    tyeeeee1 (December 6th, 2012)

  6. #5
    Member tyeeeee1's Avatar
    Join Date
    Sep 2012
    Posts
    61
    Thanks
    31
    Thanked 2 Times in 2 Posts

    Default Re: Cannot Resolve Symbol Error

    I've checked the statements that are calling the constructors for spelling errors, then I checked the classes/methods that are being called for errors in the class/method names after that I compared the non-working sections of code to the one section which I've tested before which I based the two non-working sections of code off of for any differences between the working and non-working sections.

    I'm not completely sure of what I messed up on, but I do have a few questions that may help me get closer to the solution.

    1.) In my error message, I've just noticed that the first error is for (javax.swing.JPanel) and the second is (javax.swing.JFrame), does this mean that the first line where the error is coming from is passing a JPanel and the second is passing a JFrame?

    2.) I've only just figured out how a line such as:

    CreateOptionsMenu gameWindow = new CreateOptionsMenu(gamePanel);

    works , so I'm not 100% sure if I'm using it correctly. Just so that I'm a bit more confident in my knowledge...
    Is gameWindow being set as the name by which I can reference some sort of object?
    Is the first CreateOptionsMenu a reference to the class and the second CreateOptionsMenu a reference to the specific method?
    Is gamePanel the variable being passed to the CreateOptionsMenu class?


    I'll keep looking over my code in the meantime, I probably missed something. Thanks for the help so far!

  7. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Cannot Resolve Symbol Error

    Compare the datatype of the arg being passed to the constructor to the datatype that the constructor is defined to take. Make sure they are the same.
    The compiler thinks they don't match: one is a JPanel and the other is JFrame.
    If you don't understand my answer, don't ignore it, ask a question.

  8. The Following User Says Thank You to Norm For This Useful Post:

    tyeeeee1 (December 6th, 2012)

  9. #7
    Member tyeeeee1's Avatar
    Join Date
    Sep 2012
    Posts
    61
    Thanks
    31
    Thanked 2 Times in 2 Posts

    Default Re: Cannot Resolve Symbol Error

    Oh wow... I looked at that same line at least 10 times and I never noticed that I had it set to JFrame instead of JPanel. Thanks a ton for all the help, at least I'll know to check that line specifically next time.

  10. #8
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Cannot Resolve Symbol Error

    You need to check the line that the compiler indicates is in error. Again it was telling you that it couldn't find that specific constructor, and with checking you'd see that that specific constructor wasn't there. It's not the specifics of the error that are most important here, but again the process of investigating that which the compiler tells you to investigate.

Similar Threads

  1. What's wrong with my code?? (it said cannot resolve symbol)
    By sakura_smile in forum What's Wrong With My Code?
    Replies: 23
    Last Post: June 11th, 2012, 06:55 AM
  2. Cannot find symbol ERROR
    By yacek in forum What's Wrong With My Code?
    Replies: 8
    Last Post: October 21st, 2011, 11:39 PM
  3. error :cannot find symbol
    By iswan in forum AWT / Java Swing
    Replies: 1
    Last Post: October 1st, 2011, 08:26 AM
  4. Cannot find symbol error
    By AnuR in forum What's Wrong With My Code?
    Replies: 9
    Last Post: February 23rd, 2011, 02:50 PM
  5. Need help with program please: getting symbol error
    By blinkzz in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: November 18th, 2009, 02:23 AM