Solved

test program problem

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

Author Comment

by:penfold69
Comment Utility
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
Comment Utility
 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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now