Can't figure out error message

"cannot find symbol" error

Page 1 of 1

11 Replies - 1755 Views - Last Post: 24 July 2010 - 12:20 PM Rate Topic: -----

#1 cseyerle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 18-July 10

Can't figure out error message

Posted 22 July 2010 - 08:01 PM

Project due for class as outlined in purpose statement. tried to compile get error message:
error on line 136: cannot find symbol
symbol: method score(int)
location: class AveragingGrades.
/*
	Chapter 5: 	Averaging Grades
	Programmer:	Carl Seyerle
	Course: 	CINS 136-00A
	Filename:	AveragingGrades.java
	Purpose:	This is a program that allows a user to enter
				class grades into an array of floats. The app
				will prompt for the total number of grades to
				be entered, then call a method to average the
				grades, and finially display the grades and the
				resulting average
*/

import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;

public class AveragingGrades extends Frame implements ActionListener //constructor method
{
	int counter;
	int _i = counter;
	int _Count = 0;
	int scoreAverage;
	int grade;
	int score;

	//identifies panels and components
	Panel numberPanel = new Panel();
		Label numberLabel = new Label("Enter the number of scores to average.");
		TextField numberField = new TextField(5);
		Button numberButton = new Button("Enter");

	Panel scorePanel = new Panel();
		Label scoreLabel = new Label("Enter Scores");
		TextField scoreField = new TextField(5);
		Button scoreButton = new Button("Add");

	Panel displayPanel = new Panel();
		TextArea displayTitle = new TextArea();
		TextArea displayScores = new TextArea(null,counter + 1,5,1);

	Panel averagePanel = new Panel();
		Label averageLabel = new Label("Your average of" + counter + "scores is:  " + scoreAverage + ".");
		Button clearButton = new Button("Clear");

	public AveragingGrades()
	{
		//set layouts for frame and panels
		this.setLayout(new BorderLayout());
			numberPanel.setLayout(new FlowLayout());
			scorePanel.setLayout(new FlowLayout());
			displayPanel.setLayout(new FlowLayout());
			averagePanel.setLayout(new FlowLayout());

		//add components to number panel
		numberPanel.add(numberLabel);
		numberPanel.add(numberField);
		numberPanel.add(numberButton);
		numberPanel.setBackground(Color.yellow);

		//add components to score panel
		scorePanel.add(scoreLabel);
		scorePanel.add(scoreField);
		scorePanel.add(scoreButton);
		scorePanel.setBackground(Color.lightGray);

		//add components to display panel
		displayPanel.add(displayTitle);
		displayPanel.add(displayScores);
		displayScores.setEditable(false);
		displayTitle.setEditable(false);
		displayPanel.setBackground(Color.lightGray);

		//add components to average panel
		averagePanel.add(averageLabel);
		averagePanel.add(clearButton);
		averagePanel.setBackground(Color.lightGray);

		//add panels to frame
		add(numberPanel, BorderLayout.NORTH);
		add(scorePanel, BorderLayout.WEST);
		add(displayPanel, BorderLayout.CENTER);
		add(averagePanel, BorderLayout.SOUTH);

		numberButton.addActionListener(this);
		scoreButton.addActionListener(this);
		clearButton.addActionListener(this);

		//overriding windowClosing method
		addWindowListener(
			new WindowAdapter()
			{
				public void windowClosing(WindowEvent e)
				{
					System.exit(0);
				}
			}
		);
	}



	public void AverageScore()
	{
		scoreAverage = grade / _Count;
	}



	public void actionPerformed(ActionEvent e)
	{
		String arg = e.getActionCommand();
		try
		{
			if (arg == "Enter")
			{
				int counter = Integer.parseInt(numberField.getText());
				scoreField.requestFocus();
				JOptionPane.showMessageDialog(null,"Begin entering scores.","Info",JOptionPane.INFORMATION_MESSAGE);
				scorePanel.setBackground(Color.yellow);
				numberPanel.setBackground(Color.lightGray);
			}

			if (arg == "Add")
			{
				int[] averagingGrades = new int[counter - 1];
				_Count++;

				if (_Count >= _i)
				{
					averagePanel.setBackground(Color.yellow);
					scorePanel.setBackground(Color.lightGray);
				}
				   	score(averagingGrades[_Count - 1]) = Integer.parseInt(numberField.getText());
					displayTitle.setText("Score " + _Count + " of " + _i);
					displayScores.setText("" + _Count + " " + averagingGrades[_Count - 1]);
					scoreField.setText("");
					grade += score;
			}

			if (arg == "Clear")
			{
				numberField.setText("");
				scoreField.setText("");
				numberPanel.setBackground(Color.yellow);
				scorePanel.setBackground(Color.lightGray);
				displayPanel.setBackground(Color.lightGray);
				averagePanel.setBackground(Color.lightGray);
				numberField.requestFocus();
			}
		}

		catch(NumberFormatException x)
		{
			JOptionPane.showMessageDialog(null,"Your entry was out of bounds.","Error",JOptionPane.INFORMATION_MESSAGE);
		}

	}

	public static void main(String[] args)
	{
		AveragingGrades f = new AveragingGrades();
		f.setBounds(200,200,600,300);
		f.setTitle("Averaging Grades");
		f.setVisible(true);
	} //end of main
}


This post has been edited by pbl: 22 July 2010 - 08:06 PM
Reason for edit:: Code tags fixed


Is This A Good Question/Topic? 0
  • +

Replies To: Can't figure out error message

#2 Luckless  Icon User is offline

  • </luck>
  • member icon

Reputation: 292
  • View blog
  • Posts: 1,146
  • Joined: 31-August 09

Re: Can't figure out error message

Posted 22 July 2010 - 08:11 PM

first, this concerns me:

int counter;
int _i = counter;




both of these are null and I don't see where you equate _i's value to that of counter AFTER the user hits the "Enter" button.

Secondly, why name your variables like that if it is a single word? Make _Count
into count and so forth

I think one of your many problems stem from the fact that _i is null though

This post has been edited by Luckless: 22 July 2010 - 08:14 PM

Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,858
  • Joined: 06-March 08

Re: Can't figure out error message

Posted 22 July 2010 - 08:12 PM

 score(averagingGrades[_Count - 1]) = Integer.parseInt(numberField.getText()); 



In Java xyz(param) invokes a method
first the method score(int) does not exists

second a method returns a value... if you have a method sinus() that returns the sin of an angle

sinus(90) = whatever does not make sense it show be

sin = sinus(90);
Was This Post Helpful? 0
  • +
  • -

#4 bcranger  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,199
  • Joined: 01-February 10

Re: Can't figure out error message

Posted 22 July 2010 - 08:49 PM

View PostLuckless, on 22 July 2010 - 07:11 PM, said:

first, this concerns me:

int counter;
int _i = counter;




both of these are null and I don't see where you equate _i's value to that of counter AFTER the user hits the "Enter" button.

Secondly, why name your variables like that if it is a single word? Make _Count
into count and so forth

I think one of your many problems stem from the fact that _i is null though


Luckless, both those variables are 0. An int cannot be null. An Integer can be null. The default value for ints are 0, Integers are null :)
Was This Post Helpful? 0
  • +
  • -

#5 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Can't figure out error message

Posted 22 July 2010 - 08:59 PM

This message tells you everything you need to know:

Quote

error on line 136: cannot find symbol
symbol: method score(int)
location: class AveragingGrades.


It's telling you it cannot find a method named score, and from looking through the code you provided there is indeed no method named score. Nowadays our compilers (normally) give us pretty descriptive error message, and this is one such case, so let's break it down:

  • Line 1: Error on line 136: ; this is saying on line #136 there is an error (so start there looking for your issue. Cannot find symbol; this is saying that on line #136 you are referencing something that your compiler cannot locate.
  • Line 2: Symbol: method score(int); This is the heart of your problem, it's telling you the symbol it cannot find is named score(int, so from there start going through your code looking for the method score expecting a parameter of type int. If you cant find it then surely your compiler cannot find it.
  • Line 3: Location: Class AveragingGrades; This line is very self explanatory, there error is occurring in the class AveragingGrades


So when your compiler is giving you an error message start looking at them the way outlines here and it will go a long way in helping you to start debugging your code effectively :)
Was This Post Helpful? 2
  • +
  • -

#6 SpeedisaVirus  Icon User is offline

  • Baller
  • member icon

Reputation: 114
  • View blog
  • Posts: 855
  • Joined: 06-October 08

Re: Can't figure out error message

Posted 22 July 2010 - 09:04 PM

1. It's bad practice for safety and readability to not initialize variables regardless of default values.

2. Why assign a variable you assume to take a default value to a variable that will take the same default value.


The line pbl pointed out jumped at me in a fast scroll. Seriously wrong. You are invoking a function and attempting to assign to it. You can't sensibly (assuming the function existed) assign to a return value. What does it accomplish.

This post has been edited by SpeedisaVirus: 22 July 2010 - 09:07 PM

Was This Post Helpful? 0
  • +
  • -

#7 cseyerle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 18-July 10

Re: Can't figure out error message

Posted 23 July 2010 - 02:33 PM

Okay,
Thank you for the info, but i'm still slightly confused as to how to build the array averagingGrades[]. you see, within my frame of 4 panels i'm trying to:
--with the focus starting in the 'numberField' the user inputs how many scores they will enter for averaging...i am trying to build an array 'averagingGrades[]' i would like to that singularly with a button push event.
--focus will shift to the 'numberField' where the user will start to enter scores. i want to use the 'numberButton' to count the number of push events so that the number of pushes equals the number entered in the 'numberField'. what i'm having trouble understanding is, is it possible to build the array 'averagingGrades[]' within this button counting event. my instructor suggested to move my the array assignment to the "add" section and pass it on as an argument. i though that is what i was doing. instead i ended up creating a new method. any suggestions as to how i can accomplish my goal?

Thanks
Was This Post Helpful? 0
  • +
  • -

#8 cseyerle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 18-July 10

Re: Can't figure out error message

Posted 23 July 2010 - 05:26 PM

So, i removed the (averaging[count - 1]) reference and the error message was taken care of, but i still am not getting the results that i'm trying for in the above explanation. any clues as to how i should proceed from here?
Was This Post Helpful? 0
  • +
  • -

#9 Codebug  Icon User is offline

  • D.I.C Head

Reputation: 31
  • View blog
  • Posts: 244
  • Joined: 11-October 09

Re: Can't figure out error message

Posted 23 July 2010 - 09:37 PM

View Postcseyerle, on 23 July 2010 - 04:26 PM, said:

So, i removed the (averaging[count - 1]) reference and the error message was taken care of, but i still am not getting the results that i'm trying for in the above explanation. any clues as to how i should proceed from here?


Can you tell us what you are trying to accomplish with this part of the code:

score(averagingGrades[_Count - 1]) = Integer.parseInt(numberField.getText());



you said you removed (averaging[count - 1]). What did you replace it with? I'm not really sure what you are trying to accomplish here but it looks like you want to assign the Integer that is parsed to some variable like this:

 yourVariable = Integer.parseInt(numberField.getText());



Unless I am understanding this out of context, it is really strange that you were trying to take a value returned by a method and assign it to another method. If you could tell us what exactly you were trying to do there, it would be a big help. :)

This post has been edited by Codebug: 23 July 2010 - 09:40 PM

Was This Post Helpful? 0
  • +
  • -

#10 cseyerle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 18-July 10

Re: Can't figure out error message

Posted 23 July 2010 - 10:17 PM

Okay, this is the problem we have for my basic java programming class: Write a Java program that allows you to enter your grades in the course into an array of floats. At the beginning of the program, the application should prompt you for the total number of grades you intend to enter. After entering the grades, the application should call a method to average the grades. Display the grades and the resulting average.

Here is what I want to do (if possible), I would like to define the size of the array with user input. Once the size has been determined the user then can input the grades that the program is to average. I want to display the individual grades, the number of grades, and the average. My answer hinges on whether the elements of an array can be built singlarly through a button event.

i'm still slightly confused as to how to build an array averagingGrades[].
you see, within my frame of 4 panels i'm trying to:
--with the focus starting in the 'numberField' the user inputs how many scores they will enter for averaging (this value sets the size of the array)
--focus will shift to the 'numberField' where the user will start to enter scores. i want to use the 'numberButton' to count the number of push events so that the number of pushes equals the number entered in the 'numberField'. all the while a running average is displayed in the averagePanel and the individual scores are displayed in the displayPanel.

What i'm having trouble understanding is, is it possible to build the array 'averagingGrades[]' within this button counting event. my instructor suggested to move my the array assignment to the "add" section and pass it on as an argument. i though that is what i was doing. The following attempt will compile, but I get an "Execption in thread "AWT-EventQueue-0" java.lan.ArrayIndexOutOfBounds:0" in the cmd.exe window after I click the "Add" button.

any advise will be greatly appreciated,

Here is a copy of the code:

/*
	Chapter 5: 	Averaging Grades
	Programmer:	Carl Seyerle
	Course: 	CINS 136-00A
	Filename:	AveragingGrades.java
	Purpose:	This is a program that allows a user to enter
				class grades into an array of floats. The app
				will prompt for the total number of grades to
				be entered, then call a method to average the
				grades, and finially display the grades and the
				resulting average
*/

import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;

public class AveragingGrades extends Frame implements ActionListener //constructor method
{
	int counter = 0;
	int scoreAverage = 0;
	int totalScore = 0;
	int score = 0;
	int numInLoop = 0;
	int[] averagingGrades = new int[counter];


	//identifies panels and components
	Panel numberPanel = new Panel();
		Label numberLabel = new Label("Enter the number of scores to average.");
		TextField numberField = new TextField(5);
		Button numberButton = new Button("Enter");

	Panel scorePanel = new Panel();
		Label scoreLabel = new Label("Enter Scores");
		TextField scoreField = new TextField(5);
		Button scoreButton = new Button("Add");

	Panel displayPanel = new Panel();
		TextArea displayTitle = new TextArea();
		TextArea displayScores = new TextArea(null,counter + 1,5,1);

	Panel averagePanel = new Panel();
		Label averageLabel = new Label("The average of " + numInLoop + " scores is:  " + scoreAverage + ".");
		Button clearButton = new Button("Clear");

	public AveragingGrades()
	{
		//set layouts for frame and panels
		this.setLayout(new BorderLayout());
			numberPanel.setLayout(new FlowLayout());
			scorePanel.setLayout(new GridLayout(3,1,10,10));
			displayPanel.setLayout(new GridLayout(2,1,10,10));
			averagePanel.setLayout(new FlowLayout());

		//add components to number panel
		numberPanel.add(numberLabel);
		numberPanel.add(numberField);
		numberPanel.add(numberButton);
		numberPanel.setBackground(Color.yellow);

		//add components to score panel
		scorePanel.add(scoreLabel);
		scorePanel.add(scoreField);
		scorePanel.add(scoreButton);
		scorePanel.setBackground(Color.lightGray);

		//add components to display panel
		displayPanel.add(displayTitle);
		displayPanel.add(displayScores);
		displayScores.setEditable(false);
		displayTitle.setEditable(false);
		displayPanel.setBackground(Color.lightGray);

		//add components to average panel
		averagePanel.add(averageLabel);
		averagePanel.add(clearButton);
		averagePanel.setBackground(Color.lightGray);

		//add panels to frame
		add(numberPanel, BorderLayout.NORTH);
		add(scorePanel, BorderLayout.WEST);
		add(displayPanel, BorderLayout.CENTER);
		add(averagePanel, BorderLayout.SOUTH);

		numberButton.addActionListener(this);
		scoreButton.addActionListener(this);
		clearButton.addActionListener(this);

		//overriding windowClosing method
		addWindowListener(
			new WindowAdapter()
			{
				public void windowClosing(WindowEvent e)
				{
					System.exit(0);
				}
			}
		);
	}



	//public void AverageScore()
	//{
	//	for (int i=0; i<numInLoop; i++)
	//	totalScore += averagingScores[counter];
	//	scoreAverage = totalScore / numInLoop;
//
	//}



	public void actionPerformed(ActionEvent e)
	{
		String arg = e.getActionCommand();
		try
		{
			if (arg == "Enter")
			{
				int counter = Integer.parseInt(numberField.getText());
				scoreField.requestFocus();
				JOptionPane.showMessageDialog(null,
							"You have decided to enter " + counter + " scores.\nBegin entering scores.","Info",JOptionPane.INFORMATION_MESSAGE);
				scorePanel.setBackground(Color.yellow);
				numberPanel.setBackground(Color.lightGray);
				numberField.setBackground(Color.lightGray);
			}

			if (arg == "Add")
			{

				if (numInLoop >= counter)
				{
					averagePanel.setBackground(Color.yellow);
					scorePanel.setBackground(Color.lightGray);
				}
				   	score = Integer.parseInt(numberField.getText());
				   	averagingGrades[numInLoop] = score;
				   	numInLoop++;
					displayTitle.setText("Score " + numInLoop + " of " + counter);
					displayScores.setText("" + numInLoop + " " + score + "\n");
					scoreField.setText("");
					//AverageScore();
			}

			if (arg == "Clear")
			{
				numberField.requestFocus();
				numberField.setText("");
				scoreField.setText("");
				numberPanel.setBackground(Color.yellow);
				scorePanel.setBackground(Color.lightGray);
				displayPanel.setBackground(Color.lightGray);
				averagePanel.setBackground(Color.lightGray);

			}
		}

		catch(NumberFormatException x)
		{
			JOptionPane.showMessageDialog(null,"Your entry was out of bounds.","Error",JOptionPane.INFORMATION_MESSAGE);
		}

	}

	public static void main(String[] args)
	{
		AveragingGrades f = new AveragingGrades();
		f.setBounds(200,200,400,300);
		f.setTitle("Averaging Grades");
		f.setVisible(true);
	} //end of main
}



This post has been edited by cseyerle: 23 July 2010 - 10:20 PM

Was This Post Helpful? 0
  • +
  • -

#11 Handler  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 199
  • Joined: 01-April 10

Re: Can't figure out error message

Posted 24 July 2010 - 01:41 AM

the problem begins at line 27:

int[] averagingGrades = new int[counter];


change that to:

int[] averagingGrades;


then add after line 123:

averagingGrades = new int[counter];


that should work then

the reason why it doesn't work is because you are making the size 0
so all you do now is create it after the user enters how many scores there are

This post has been edited by Handler: 24 July 2010 - 01:44 AM

Was This Post Helpful? 1
  • +
  • -

#12 cseyerle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 18-July 10

Re: Can't figure out error message

Posted 24 July 2010 - 12:20 PM

sweet...that helped now to work on getting the 'frame' formatted...

Thanks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1