GUI Java Cannot Find Symbol Error

Not understanding problem

  • (2 Pages)
  • +
  • 1
  • 2

23 Replies - 3860 Views - Last Post: 16 March 2008 - 04:41 PM Rate Topic: -----

#1 MFam  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 03-March 08

GUI Java Cannot Find Symbol Error

Post icon  Posted 06 March 2008 - 10:54 AM

I cannot seem to figure out the problem. Can anyone help!!!

Here is error:

gui.java:122: cannot find symbol
symbol : method getnumItem(int)
location: class NameRestock
NameRestock aryProd = (NameRestock) inventory.getnumItem(currentProdno);
** The arrow points directly at the period between inventory and getnumItem.




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

class GUI extends JFrame {
	private NameRestock inventory;
//	private int currentProdno = 0; 
	private JTextField jtfprdItem; //1	  
	private JTextField jtfprdName; //2	   
	private JTextField jtfprdUnit; //3
	private JTextField jtfprdPrice;//4
	private JTextField jtfTotal;   //5   getresult()
	private JTextField jtfReStock; //6   getrestock()
	private JTextField jtfstrCName;//7		
	private JTextField jtfinvTotal;//8		
	private JButton btnNext;			
	
	GUI(NameRestock inventory) {
		super("Inventory Part 4 Program");
		//this.inventory = inventory;
		
		JPanel jp;
		JLabel jl;
		JPanel outerPanel = new JPanel();
		outerPanel.setLayout(new BoxLayout(outerPanel, BoxLayout.Y_AXIS));
 
		JPanel titlePanel = new JPanel();
		titlePanel.setLayout(new FlowLayout(FlowLayout.CENTER));
		jl = new JLabel("Inventory Part 4");
		titlePanel.add(jl);
		outerPanel.add(titlePanel);
 
		JPanel numberPanel = new JPanel();
		numberPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
		jl = new JLabel("   Number: " );		
		numberPanel.add(jl);
		jtfprdItem = new JTextField (1);
		jtfprdItem.setEditable(false);
		numberPanel.add(jtfprdItem);
		outerPanel.add(numberPanel);
		
		JPanel number1Panel = new JPanel();
		number1Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
		jl = new JLabel("   Name: " );		
		number1Panel.add(jl);
		jtfprdName = new JTextField (2);
		jtfprdName.setEditable(false);
		number1Panel.add(jtfprdName);
		outerPanel.add(number1Panel);
		
		JPanel number2Panel = new JPanel();
		number2Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
		jl = new JLabel("   Units: " );		
		number2Panel.add(jl);
		jtfprdUnit = new JTextField(3);	
		jtfprdUnit.setEditable(false);	 
		number2Panel.add(jtfprdUnit);	  
		outerPanel.add(number2Panel);
		
		JPanel number3Panel = new JPanel();
		number3Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
		jl = new JLabel("   Price: " );		
		number3Panel.add(jl);
		jtfprdPrice = new JTextField(4);	
		jtfprdPrice.setEditable(false);   
		number3Panel.add(jtfprdPrice);	   
		outerPanel.add(number3Panel);
		
		JPanel number4Panel = new JPanel();
		number4Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
		jl = new JLabel("   Total: $ " );		
		number4Panel.add(jl);
		jtfTotal = new JTextField(5);
		jtfTotal.setEditable(false);
		number4Panel.add(jtfTotal);
		outerPanel.add(number4Panel);
		
		JPanel number5Panel = new JPanel();
		number5Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
		jl = new JLabel("Restocking Fee: $ " );		
		number5Panel.add(jl);
		jtfReStock = new JTextField(6);
		jtfReStock.setEditable(false);
		number5Panel.add(jtfReStock);
		outerPanel.add(number5Panel);

		JPanel number6Panel = new JPanel();
		number5Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
		jl = new JLabel("Restocking Fee: $ " );		
		number5Panel.add(jl);
		jtfstrCName = new JTextField(7);
		jtfstrCName.setEditable(false);
		number5Panel.add(jtfstrCName);
		outerPanel.add(number6Panel);
		
		JPanel number7Panel = new JPanel();
		number6Panel.setLayout(new FlowLayout(FlowLayout.CENTER));
		jl = new JLabel("Total Invenory Value: $" );
		number6Panel.add(jl);
		jtfTotal = new JTextField(8);
		jtfTotal.setEditable(false);
		outerPanel.add(number7Panel);
		
		JPanel jpButtons = new JPanel();
		JButton jbNext = new JButton("Next");
		jbNext.addActionListener(new NextButtonHandler());
		jpButtons.add(jbNext);
		outerPanel.add(jpButtons);
 
		updateFields();					
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(160, 120, 400, 300);
 
		setContentPane(outerPanel);
		setResizable(false);
		setVisible(true);
	   
	  }
 
		public void updateFields() {
		NameRestock aryProd = (NameRestock) inventory.getnumItem(currentProdno);
		jtfprdItem.setText(String.format("%s", inventory.getnumItem()));
		jtfprdName.setText(String.format("%s", inventory.getstrName()));
		jtfprdUnit.setText(String.format("%s", inventory.getnumUnit()));
		jtfprdPrice.setText(String.format("%.2f", inventory.getnumPrice()));
		jtfTotal.setText(String.format("%.2f", inventory.getResult()));
		jtfReStock.setText(String.format("%.2f", inventory.getRestock()));
		jtfstrCName.setText(String.format("%s", inventory.getstrCName()));
		//jtfinvTotal.setText(String.format("%.2f", inventory.getstrCName()));
	} // end updateFields()
 
	class NextButtonHandler implements ActionListener {
		public void actionPerformed(ActionEvent event) {
//			++currentProdno;
			updateFields();
		}
	}
 
} // end GUI class




Is This A Good Question/Topic? 0
  • +

Replies To: GUI Java Cannot Find Symbol Error

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4332
  • View blog
  • Posts: 12,127
  • Joined: 18-April 07

Re: GUI Java Cannot Find Symbol Error

Posted 06 March 2008 - 11:01 AM

Check your NameRestock class. You have either...

1) Not defined the function getnumItem()
2) You defined the function but have wrong capitalization (could it be getNumItem()?)
3) Or the function is not specified as public or in a scope that can be seen by your GUI class.

So check out that class and see which one it could be. If you still can't find it, post your NameRestock class code.

:)
Was This Post Helpful? 0
  • +
  • -

#3 MFam  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 03-March 08

Re: GUI Java Cannot Find Symbol Error

Posted 06 March 2008 - 12:54 PM

View PostMartyr2, on 6 Mar, 2008 - 11:01 AM, said:

Check your NameRestock class. You have either...

1) Not defined the function getnumItem()
2) You defined the function but have wrong capitalization (could it be getNumItem()?)
3) Or the function is not specified as public or in a scope that can be seen by your GUI class.

So check out that class and see which one it could be. If you still can't find it, post your NameRestock class code.

:)



Thanks for looking at this with me! I have looked at the capitilizations and did not see any problems. I made sure the getnumItem and setnumItem functions were located in the file. They are both public. Hope you can help!

Here is error:
E:\InFormation Technology Degree\IT215\Week Seven\inventory2>javac GUI.java
GUI.java:122: cannot find symbol
symbol : method getaryNum(int)
location: class NameRestock
NameRestock aryProd = (NameRestock) inventory.getaryNum(currentProdno);
^
1 error


//NameRestock.java
public class NameRestock extends Product
{		   
	  //the NameReStock subclass adds one field	  
	  public String strCName;

	  // the NameRestock sublass has one Constructor 
	  public NameRestock(int prdItem, String prdName, int prdUnit, double prdPrice, String newName)
	  {
		 super(prdItem, prdName, prdUnit, prdPrice);
		 strCName = newName;
		 getstrCName();
		  
	  } //end four-argument constructor

	  //the NameRestock subclass adds one method
	  public void setName(String newName)
	  {
		 strCName = newName;
	  }

	  public String getstrCName()
	  {
		 return strCName;
	  }

 
	 //get getRestock
	  public double getRestock()
	  {
		 return ((numPrice * numUnit) + ((numPrice * numUnit) * .05));

	  } //end method getRestock

	  //get results
	  public double getResult()
	  {
		 return numPrice * numUnit;
	  } //end method getResult


	  // toString returns result to string
	  public String toString()
	  {
		
		 return String.format("%-6d %-18s %-5d $%-6.2f $%-8.2f $%-10.2f %s",
							 numItem, strName, numUnit, numPrice, getResult(),getRestock(),getstrCName());
					
	  } // end method toString


	  // set numItem
	  public void setnumItem(int prdItem)
	  {
		 numItem = prdItem;
	  } //end method set numItem


	  //get numItem
	  public int getnumItem()
	  {
		 return numItem;
	  } //end method get numItem

} // end of NameRestock class


Was This Post Helpful? 0
  • +
  • -

#4 letthecolorsrumble  Icon User is offline

  • Student of The Sun
  • member icon

Reputation: 27
  • View blog
  • Posts: 555
  • Joined: 07-November 07

Re: GUI Java Cannot Find Symbol Error

Posted 06 March 2008 - 01:09 PM

There is no getaryNum(int) method defined in the class NameRestock.

Is it defined in the super-class of NameRestock?

This post has been edited by letthecolorsrumble: 06 March 2008 - 01:11 PM

Was This Post Helpful? 0
  • +
  • -

#5 MFam  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 03-March 08

Re: GUI Java Cannot Find Symbol Error

Posted 06 March 2008 - 01:53 PM

My bad!! That was a tested error. I have the code back to original! Trying to figure it out!

Here is the error:
E:\InFormation Technology Degree\IT215\Week Seven\inventory2>javac GUI.java
GUI.java:122: cannot find symbol
symbol : method getnumItem(int)
location: class NameRestock
NameRestock aryProd = (NameRestock) inventory.getnumItem(currentProdno);

^
1 error
Was This Post Helpful? 0
  • +
  • -

#6 letthecolorsrumble  Icon User is offline

  • Student of The Sun
  • member icon

Reputation: 27
  • View blog
  • Posts: 555
  • Joined: 07-November 07

Re: GUI Java Cannot Find Symbol Error

Posted 06 March 2008 - 02:19 PM

Anyway you see it, getnumItem() method would return an int. But you want to create an object of NameRestock, so there is definitely a type mismatch.

Also in your NameRestock class getnumItem() does not take any arguments.
Was This Post Helpful? 0
  • +
  • -

#7 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4332
  • View blog
  • Posts: 12,127
  • Joined: 18-April 07

Re: GUI Java Cannot Find Symbol Error

Posted 06 March 2008 - 03:35 PM

View Postletthecolorsrumble, on 6 Mar, 2008 - 01:19 PM, said:

Anyway you see it, getnumItem() method would return an int. But you want to create an object of NameRestock, so there is definitely a type mismatch.

Also in your NameRestock class getnumItem() does not take any arguments.



^^ He is certainly right on this one on both counts. Told you the error was back in NameRestock. ;)

And as I told you, someone else could jump in and answer this before I could get back to you. That is the benefit of keeping your questions on the board rather than me answering this in PM for you. DIC is a team oriented environment.
Was This Post Helpful? 0
  • +
  • -

#8 MFam  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 03-March 08

Re: GUI Java Cannot Find Symbol Error

Posted 06 March 2008 - 05:56 PM

Having commented out the "//NameRestock aryProd = (NameRestock) inventory.getnumItem(currentProdno);" and it does compile at this point. Realizing I have some getNumItem() issues. Shouldn't I be able to view its present contents. How do I kick this off?
Was This Post Helpful? 0
  • +
  • -

#9 letthecolorsrumble  Icon User is offline

  • Student of The Sun
  • member icon

Reputation: 27
  • View blog
  • Posts: 555
  • Joined: 07-November 07

Re: GUI Java Cannot Find Symbol Error

Posted 06 March 2008 - 06:32 PM

There is no main() in your GUI program yet, so you won't be able to see anything.

    public static void main(String[] args) {    	
    	
    	GUI myGui = new GUI();  //not exactly this but close to this    	
    	
    }



Also the paint() method in the GUI class is missing.
Was This Post Helpful? 0
  • +
  • -

#10 quim  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 18
  • View blog
  • Posts: 182
  • Joined: 11-December 05

Re: GUI Java Cannot Find Symbol Error

Posted 06 March 2008 - 06:39 PM

"This is the fourth post that your're making about the same program.
but your' not posting all the code. this way other people may not know what
you're talking about without going back to the other posts."


*Now solution:
1) go to InventoryPart1.java and instantiate GUI -- like this
       NameRestock aryProd[] = new NameRestock[4];

      aryProd[0] = new NameRestock(1, "Hammers", 5, 20.12,"JBSandoz");
      aryProd[1] = new NameRestock(2, "Electric Drills", 3, 78.39,"ToolTime");
      aryProd[2] = new NameRestock(3, "Nails", 600, .15,"NailRoom");
      aryProd[3] = new NameRestock(4, "Wood Screws", 300, .99,"WoodHouse");


      //Sort Products.
      SortProductArray(aryProd); //call Bubble Sorth method
      System.out.println();//blank line

       // this is where you instantiate 
      // create GUI -- your passing ARRAY so go to the constructor and check parameter to ARRAY
	  GUI gui = new GUI( aryProd );


this is what you should get after compiling -- But, as you can see you still have do so
some work with the GUI ( user interface )
Attached Image
Was This Post Helpful? 0
  • +
  • -

#11 MFam  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 03-March 08

Re: GUI Java Cannot Find Symbol Error

Posted 06 March 2008 - 08:13 PM

View Postquim, on 6 Mar, 2008 - 06:39 PM, said:

"This is the fourth post that your're making about the same program.
but your' not posting all the code. this way other people may not know what
you're talking about without going back to the other posts."


*Now solution:
1) go to InventoryPart1.java and instantiate GUI -- like this
       NameRestock aryProd[] = new NameRestock[4];

      aryProd[0] = new NameRestock(1, "Hammers", 5, 20.12,"JBSandoz");
      aryProd[1] = new NameRestock(2, "Electric Drills", 3, 78.39,"ToolTime");
      aryProd[2] = new NameRestock(3, "Nails", 600, .15,"NailRoom");
      aryProd[3] = new NameRestock(4, "Wood Screws", 300, .99,"WoodHouse");


      //Sort Products.
      SortProductArray(aryProd); //call Bubble Sorth method
      System.out.println();//blank line

       // this is where you instantiate 
      // create GUI -- your passing ARRAY so go to the constructor and check parameter to ARRAY
	  GUI gui = new GUI( aryProd );


this is what you should get after compiling -- But, as you can see you still have do so
some work with the GUI ( user interface )
Attachment attachment



Thank you for Helping! I will post all future posting to this post only!
I did try to put all the code I am using. Guess I am not using the posting tools properly. So I have posted a text file that holds the code for each file. Would appreciate any feedback possible! I am seeking to understand in the minimal timeframe left!

Again Thanks!

Also, I notice you built your own GUI to check the Inventory program. I am compiling my GUI presently and it compiles properly. I realize this is not necessarily true. Apparently something is terribly wrong. Maybe I need to start from scratch. Hope not! Feedback appreciated!

Attached File(s)


This post has been edited by MFam: 06 March 2008 - 08:14 PM

Was This Post Helpful? 0
  • +
  • -

#12 quim  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 18
  • View blog
  • Posts: 182
  • Joined: 11-December 05

Re: GUI Java Cannot Find Symbol Error

Posted 06 March 2008 - 09:19 PM

Quote

Also, I notice you built your own GUI to check the Inventory program

No, this is the same code that you wrote, i just had to change some variable and
modify the constructor parameter to be an array.

here are the .java files:
Attached File  Product.txt (2.02K)
Number of downloads: 123Attached File  NameRestock.txt (1.32K)
Number of downloads: 121Attached File  InventoryPart1.txt (4.25K)
Number of downloads: 124Attached File  GUI.txt (6.25K)
Number of downloads: 129
Was This Post Helpful? 0
  • +
  • -

#13 MFam  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 03-March 08

Re: GUI Java Cannot Find Symbol Error

Posted 07 March 2008 - 07:00 PM

View Postquim, on 6 Mar, 2008 - 09:19 PM, said:

Quote

Also, I notice you built your own GUI to check the Inventory program

No, this is the same code that you wrote, i just had to change some variable and
modify the constructor parameter to be an array.

here are the .java files:
Attachment attachmentAttachment attachmentAttachment attachmentAttachment attachment


Wanted to thank you for the help!

I have been working on the currency portion of the code and now have this corrected. I was able to manipulate some of the code you helped me with to correct my decimal placing issue.

I am now trying to get the total inventory value to show up on the GUI. I believe I am approaching this correctly but it doesn't seem to show up in the field. Again, I think I have the correct approach but maybe I am setting something up incorrectly. Can you look at my NameRestock.java file where I greated a totValue() method and tell me what I am doing wrong. See attachment!

Attached File(s)


This post has been edited by MFam: 07 March 2008 - 09:41 PM

Was This Post Helpful? 0
  • +
  • -

#14 MFam  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 03-March 08

Re: GUI Java Cannot Find Symbol Error

Posted 07 March 2008 - 09:39 PM

I need to know how to add up Restock values. I created a getrestock() method that will tally up each arrays info and then add 5%. I now need to add the total array counts worth of restock prices for a grand total. Please need help soon. I have been trying all kinds of things with my NameRestock.java file. I have added gettotValue() and settotValue() methods and tried to manipulate the correct result. I have not been successful.

Here are all the files in one text file for viewing!

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#15 quim  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 18
  • View blog
  • Posts: 182
  • Joined: 11-December 05

Re: GUI Java Cannot Find Symbol Error

Posted 08 March 2008 - 06:59 AM

Quote

I am now trying to get the total inventory value to show up on the GUI...


you don't need to declare the instance variable public double totValue in the NameRestock
you have already defined
 
     //get results
      public double getResult()
      {
         return numPrice * numUnit;
      } //end method getResult



getResult() will calculate the total amount "money" of one product "element in array"
to get the total amount of inventory "money" you need to get the result of each product and add
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2