编译时出现错误消息

时间:2014-04-16 03:53:24

标签: java

import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Scanner;
import java.lang.String;

public class ProgramData8
{

   public static void main(String[] args)throws IOException
   {

      StackClass stack = new StackClass();
      QueueClass queue = new QueueClass();
      IntElement x = new IntElement(0);
      int num;

      StringTokenizer tokenizer;
      BufferedReader keyboard = new BufferedReader (new InputStreamReader(System.in));
      System.out.print("Please enter the numbers.");

      tokenizer = new StringTokenizer(keyboard.readLine());
      stack.push(x);
      queue.addQueue(x);
      num = Integer.parseInt(tokenizer.nextToken());

      while(num != -999)
      {
         x.setNum(num);
         switch(num%4)
         {
            case 0: stack.push(x);
               break;
            case 1: 
               if(!stack.isEmptyStack())
               {
                  System.out.println("Stack Element = " + stack.top());
                  stack.pop();
               }
               else
                  System.out.println("Sorry, the stack is empty.");
               break;
            case 2: queue.addQueue(x);
               break;
            case 3: 
               if(!queue.isEmptyQueue())
               {
                  System.out.println("Queue Element = " + queue.front());
                  queue.deleteQueue();
               }
               else
                  System.out.println("Sorry, the queue is empty.");
               break;
         }
         num = Integer.parseInt(tokenizer.nextToken());
      }
      System.out.println("Stack Elements: " );
      while(!stack.isEmptyStack())
      {
         System.out.print(stack.top() + " " );
         stack.pop();
      }
      System.out.println();
      System.out.print("Queue Elements: " );
      while(!queue.isEmptyQueue())
      {
         System.out.print(queue.front() + " " );
         queue.deleteQueue();
      }
      System.out.println();
   }
}

我一直收到以下错误。

ProgramData8.java:13: error: cannot find symbol
      StackClass stack = new StackClass();
      ^
  symbol:   class StackClass
  location: class ProgramData8
ProgramData8.java:13: error: cannot find symbol
      StackClass stack = new StackClass();
                             ^
  symbol:   class StackClass
  location: class ProgramData8
ProgramData8.java:14: error: cannot find symbol
      QueueClass queue = new QueueClass();
      ^
  symbol:   class QueueClass
  location: class ProgramData8
ProgramData8.java:14: error: cannot find symbol
      QueueClass queue = new QueueClass();
                             ^
  symbol:   class QueueClass
  location: class ProgramData8
ProgramData8.java:15: error: cannot find symbol
      IntElement x = new IntElement(0);
      ^
  symbol:   class IntElement
  location: class ProgramData8
ProgramData8.java:15: error: cannot find symbol
      IntElement x = new IntElement(0);
                         ^
  symbol:   class IntElement
  location: class ProgramData8
6 errors

 ----jGRASP wedge2: exit code for process is 1.
 ----jGRASP: operation complete.

2 个答案:

答案 0 :(得分:1)

同意user3414693

要使用这个类,你需要做其中一个。(可能还有其他一些方法)

1.将它们放在相同的包装中,最好将它们公开

2.将所有这些课程保存在一个文件中(不推荐)。

3.使用package概念将所有这些类放在同一目录中,而不是import该包。

(对不起,如果我遗漏了什么)

答案 1 :(得分:0)

  

找不到符号

此错误表示该变量未声明或在您的范围内不存在。

此处您引用的课程不在您的范围内。导入它们。在eclipse IDE中,使用

  

control + Shift + O

导入类。

在这种情况下,您尚未导入自定义类,您只有这些导入:

import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Scanner;
import java.lang.String;

您需要导入StackClassQueueClass和所有其他自定义类。