[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 302
  • Last Modified:

object returned but cannot access its methods?

Three classes pasted below, this is a linked list implementation. I have a button on my GUI that should inform the user of the object in the front of the queue. I cannot access the methods of an employye object? Any pointers?

Tks,
Owen.


private void frontButtonActionPerformed(java.awt.event.ActionEvent evt)
 {
myQueue.front();
How do I access the methods or properties of my employee object?????
Netbeans autocomplete won't bring up any of these? I want to put one of it's
}
public class Node {
    private Object element;
    private Node next;
    
    public Node()
    {
        this(null,null);
    }
    public Node(Object e, Node n)
    {
        element = e;
        next = n;
    }
    public void setElement(Object newElement)
    {
        element = newElement;
    }
    public void setNext(Node newNext)
    {
        next = newNext;
    }
    public Object getElement()
    {
        return element;
    }
    public Node getNext()
    {
        return next;
    }
   
    }
################################################
 
public class Employee {
    private  int age,empNum;
    private String fName, lName;
    
    public Employee(int empNum, String fName, String lName, int age)
    {
        this.age = age;
        this.empNum = empNum;
        this.fName = fName;
        this.lName = lName;
    }
    
    public String getName()
    {
        String joinName;
        joinName = fName + lName;
        return joinName;
    }
    public int getAge()
    {
        return age;
    }
    public int getEmpNum()
    {
        return empNum;
    }
    @Override
    public String toString()
    {
        return empNum+ "\t" + fName+ " " + lName+ "\t" + age + "\n";
    }
 
}
##################################################
 
public class LinkedQueue 
{
    private Node head, tail;
    private int qSize;
    
    public LinkedQueue()
    {
        head = tail = null;
        qSize = 0;
    }
    public int size()
    {
        return qSize;
    }
    public Node getTail()
    {
        return tail;
    }
    public boolean isEmpty()
    {
    return ( head==tail );
    }
    public Object front() throws QueueEmptyException
    {if (isEmpty())
        throw new QueueEmptyException("Queue is empty");
     else
         return head.getElement();
    }
    
    public void append(Object obj)
    {
    Node node = new Node();
    node.setElement(obj);
    node.setNext(null);
    if(qSize == 0)
        head = node;
    else 
        tail.setNext(node);
    tail = node;
    qSize++;
    }
    public Object serve()throws QueueEmptyException
{
    Object obj;
    if(qSize == 0)
        throw new QueueEmptyException("Queue is empty");
    else 
    {
        obj = head.getElement();
        head = head.getNext();
        qSize--;
    }
    if(qSize == 0)
        tail = null;
    return obj;
    
}
}

Open in new window

0
OwenMoriarty
Asked:
OwenMoriarty
  • 2
  • 2
1 Solution
 
jazzIIIloveCommented:
Hi there;

Are they in the same package? What is the error line...could you write it here?

Best regards...
0
 
OwenMoriartyAuthor Commented:
C:\Documents and Settings\Me\My Documents\saprac\prac2\src\gui.java:217: cannot find symbol
symbol  : variable anEmployee
location: class gui
statusLabel.setText(anEmployee.getName());

Tks,
Owen.
0
 
OwenMoriartyAuthor Commented:
Sorry, original post does not have code that gives error.

Line 217:statusLabel.setText(anEmployee.getName());
0
 
jazzIIIloveCommented:
Hi there;

So exactly in which class (possibly main class i think) you are creating the object?..The class referring the anEmployee seems valid to me, accessors and mutators are valid...This leads me to think that you create your variable that tthe referenced class is not visible...So issue is visibility it seems...I think they are not in the same package...Maybe some classes are in <default package>, some are in another package...Let them in the same package group...If there are any other project, close them and be sure your project is the active project...

If you can send the snippet that you create your object, maybe we can process better...

Best regards...
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now