Welcome to Dream.In.Code
Become a Java Expert!

Join 150,393 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,038 people online right now. Registration is fast and FREE... Join Now!




GUI Java Cannot Find Symbol Error

2 Pages V  1 2 >  
Reply to this topicStart new topic

GUI Java Cannot Find Symbol Error, Not understanding problem

MFam
6 Mar, 2008 - 09:54 AM
Post #1

New D.I.C Head
*

Joined: 3 Mar, 2008
Posts: 41

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.




CODE

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


User is offlineProfile CardPM
+Quote Post

Martyr2
RE: GUI Java Cannot Find Symbol Error
6 Mar, 2008 - 10:01 AM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,660



Thanked: 314 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
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.

smile.gif
User is offlineProfile CardPM
+Quote Post

MFam
RE: GUI Java Cannot Find Symbol Error
6 Mar, 2008 - 11:54 AM
Post #3

New D.I.C Head
*

Joined: 3 Mar, 2008
Posts: 41

QUOTE(Martyr2 @ 6 Mar, 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.

smile.gif



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


CODE

//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

User is offlineProfile CardPM
+Quote Post

letthecolorsrumble
RE: GUI Java Cannot Find Symbol Error
6 Mar, 2008 - 12:09 PM
Post #4

Student of The Sun
Group Icon

Joined: 7 Nov, 2007
Posts: 550



Thanked: 1 times
My Contributions
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: 6 Mar, 2008 - 12:11 PM
User is offlineProfile CardPM
+Quote Post

MFam
RE: GUI Java Cannot Find Symbol Error
6 Mar, 2008 - 12:53 PM
Post #5

New D.I.C Head
*

Joined: 3 Mar, 2008
Posts: 41

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
User is offlineProfile CardPM
+Quote Post

letthecolorsrumble
RE: GUI Java Cannot Find Symbol Error
6 Mar, 2008 - 01:19 PM
Post #6

Student of The Sun
Group Icon

Joined: 7 Nov, 2007
Posts: 550



Thanked: 1 times
My Contributions
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.

User is offlineProfile CardPM
+Quote Post

Martyr2
RE: GUI Java Cannot Find Symbol Error
6 Mar, 2008 - 02:35 PM
Post #7

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,660



Thanked: 314 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
QUOTE(letthecolorsrumble @ 6 Mar, 2008 - 01: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.



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

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.
User is offlineProfile CardPM
+Quote Post

MFam
RE: GUI Java Cannot Find Symbol Error
6 Mar, 2008 - 04:56 PM
Post #8

New D.I.C Head
*

Joined: 3 Mar, 2008
Posts: 41

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?
User is offlineProfile CardPM
+Quote Post

letthecolorsrumble
RE: GUI Java Cannot Find Symbol Error
6 Mar, 2008 - 05:32 PM
Post #9

Student of The Sun
Group Icon

Joined: 7 Nov, 2007
Posts: 550



Thanked: 1 times
My Contributions
There is no main() in your GUI program yet, so you won't be able to see anything.

java

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.
User is offlineProfile CardPM
+Quote Post

quim
RE: GUI Java Cannot Find Symbol Error
6 Mar, 2008 - 05:39 PM
Post #10

D.I.C Head
Group Icon

Joined: 11 Dec, 2005
Posts: 145



Thanked: 2 times
Dream Kudos: 350
My Contributions
"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
java
       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
User is offlineProfile CardPM
+Quote Post

MFam
RE: GUI Java Cannot Find Symbol Error
6 Mar, 2008 - 07:13 PM
Post #11

New D.I.C Head
*

Joined: 3 Mar, 2008
Posts: 41

QUOTE(quim @ 6 Mar, 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
java
       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



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!

This post has been edited by MFam: 6 Mar, 2008 - 07:14 PM


Attached File(s)
Attached File  InventoryPart4.txt ( 14.1k ) Number of downloads: 30
User is offlineProfile CardPM
+Quote Post

quim
RE: GUI Java Cannot Find Symbol Error
6 Mar, 2008 - 08:19 PM
Post #12

D.I.C Head
Group Icon

Joined: 11 Dec, 2005
Posts: 145



Thanked: 2 times
Dream Kudos: 350
My Contributions
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: 36
Attached File  NameRestock.txt ( 1.32k ) Number of downloads: 34
Attached File  InventoryPart1.txt ( 4.25k ) Number of downloads: 33
Attached File  GUI.txt ( 6.25k ) Number of downloads: 33

User is offlineProfile CardPM
+Quote Post

2 Pages V  1 2 >
Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 06:01PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month