Solved

test program problem

Posted on 2002-05-08
3
219 Views
Last Modified: 2010-03-31
0
Comment
Question by:penfold69
3 Comments
 

Author Comment

by:penfold69
ID: 6997175
i have a problem with my test program, their seems to be an error in it!

TestQueue.java:39: Can't make a static reference to nonstatic variable Position in class QueueNode.

                                   Position = uuInOut.ReadInt();


some variables are declared in the class below
class QueueNode
{

     public int Position;
     public String DocumentName;
     public String Owner;
     public int Size;
     
     public QueueNode next;
     public QueueNode previous;
     
}


import uuInOut;
class TestQueue extends Queue
{
     static void displayMenu()
     {
          System.out.println("--------------------------------");
          System.out.println("     Printer Queue System       ");
          System.out.println("--------------------------------");
          System.out.println("                                ");
          System.out.println("Option\tAction");
          System.out.println("   ");
          System.out.println("1\tAdd document");
          System.out.println("2\tPrint a Document");
          System.out.println("3\tDisplay Contents of Queue");
          System.out.println("    ");
          System.out.println("4\tPurge the queue");
          System.out.println("5\tRemove a Document");
          System.out.println("6\tDisplay how many documents in the Queue");
          System.out.println("7\tDisplay the Size of Queue (KB)");
          System.out.println("8\tExit");
         
     }
     
     public static void main (String [] arguments)
     {
          Queue test = new Queue();
         
          int choice;
         
          displayMenu();
          System.out.println("\n Enter your choice?");
          choice = uuInOut.ReadInt();
         
          while (choice !=8)
          {
               switch (choice)
               {
                    case 1 :       System.out.println("Enter in the Job Position?");
                                   Position = uuInOut.ReadInt();
                                   test.add(Position);
                                     System.out.println("Enter in the Document Name?");
                                     DocumentName = uuInOut.ReadString();
                                   test.add(DocumentName);
                                     System.out.println("Enter in the Owner?");
                                     Owner = uuInOut.ReadInt();
                                   test.add(Owner);
                                    break;
                               
                    case 2 :       user.remove();
                                   System.out.println("Document Printed!");
                                   break;
                                   
                   case 3 :    user.displayAll();                                              
                                   break;
                                   
                    case 4 :     user.purgequeue();          
                                   break;
                                   
                    case 5 :    System.out.println("Feaure NOT added!");
                                   break;
                                   
                    case 6 :     System.out.println("All contents of Queue Displayed below!");
                                   user.getDocumentCount();
                                   break;
                                   
                    case 7 :     System.out.println("Size of queue feature NOT added!");
                                   break;
                                   
                    default:     System.out.println("Error!, Please select 1 to 8 only!");
                                   
               }
               
               displayMenu();
               System.out.println("\n Enter your choice?");
               choice = uuInOut.ReadInt();    
          }
     }
}
0
 
LVL 35

Expert Comment

by:girionis
ID: 6997230
 Either create an instance of the class QueueNode like: QueueNode qn = new QueueNode() and access the "Position" variable through the "qn" variable like: qn.Position  = uuInOut.ReadInt(); or declare your QueueNode class final or the variables in there static.

 Hope it helps.
0
 
LVL 2

Accepted Solution

by:
triso earned 100 total points
ID: 6997247
You will have to create a QueueNode object before you can use it.  Right under your line "Queue test = new Queue();" in main(), you can put "QueueNode node = new QueueNode();"

Then you will have to change "Position" to "node.Position" for each of those data members.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
factorial example 4 49
maven module vs maven project 3 47
Which non-HTML GUI front end to use with Java? 3 24
Fast way to search item into Java Array (Rhino compatible) 2 31
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question