So I have an interface program called: IstackInterface.java, which contains method declarations and it compiles fine. I put it in a package we call package abc. Now I have another java program called IArrayStack.java that says:

public class IArrayStack implements IStackInterface {  
// code goes here
}

But it doesn't compile and says symbol not found for IStackInterface. Both programs have declared package abc, and they're in the same folder. I'm not sure what to do to make this compile.

I am programming in linux.

Please help! I'm stuck and can't even start my program without understanding why this isn't working. Thanks to anyone who replies!

Edited 7 Years Ago by iamsmooth: n/a

As you said yourself, "I have a program called IstackInterface.java" . . but in your IArrayStack class, you called it IStackInterface. The two are different because of the capital 'S'. Rename it.

That was a typo, they're spelt exactly the same with same caps. Sorry... So, that's not the problem.

Well, I'm out of ideas. If this is the type of thing that you can't wait until tomorrow for, I recommend downloading an IDE such as Eclipse and using the IDE to manage your code. If you can wait until later, then I'm sure someone will realize what's going on.

If you want to post both of your classes I can paste them into Eclipse and try to help you further, but as of now, I don't know.

package CPSC331Assignment2;


IStackInterface.java:

public interface IStackInterface{


    public int push (int obj);

    public int pop ();

    public int peek ();

    public boolean empty();
    
}

IArrayStack.java:

package CPSC331Assignment2;
 
 import java.util.EmptyStackException;
 
 
 public class IArrayStack implements IStackInterface {

  // Data Fields

  /**
   *
   * The detault initial capacity
   */
   private static final int INITIAL_CAPACITY = 8;

  /**
   *
   * The underlying array of integers used to store stack contents
   *
   */
   private int[] StackContents;

  /**
   *
   * The position in the array of the current top of the stack;
   * set to −1 if the stack is currently empty
   */
   private int top;
  
   public IArrayStack () {

     StackContents = new int[INITIAL_CAPACITY];
     top = -1;
   
   }

   
   public int push (int obj) {
   
     return 0;
     
   }

   public int pop () {
   
     return 0;
   
   }

   
   public int peek () {
   
     return 0;
     
   }
   
   public boolean empty () {
   
     return true;
     
   }
 
   protected int getCapacity () {

      return 0;

   }

 
   protected int getSize () {

     return 0;

   }

   
   private void expandStack () {
   
   }

 
   private void contractStack () {
   
   }
 
 }

This is the skeleton code to which I'm supposed to work with for my assignment.

Edited 7 Years Ago by iamsmooth: n/a

Okay, I guess this has something to do with the package. I removed the package declarations from both files and it compiles. How do I get packages to work properly on linux ><?

Edited 7 Years Ago by iamsmooth: n/a

Oh. I should have noticed that to begin with - when you declare a package, on the file system, it has to be in that folder. So your two classes that were declared as the package CPSC331Assignment2 would have to be in a folder called CPSC331Assignment2. It has nothing to do with Linux.

Edited 7 Years Ago by BestJewSinceJC: n/a

K I put it in a folder named after the package, still not compiling. Same symbol not found error.

Hmph. Well I looked it up and what I said wasn't really true - by convention, you'd do what I said above, but it isn't required by the language. Either way, if you have this folder structure:

cmscassignment->(class1.java, class2.java)
and class1.java and class2.java both say package cmscassignment; at the top, it should work. If that isn't working for you I'd suggest using an IDE to create your file structure for you, then just drag and drop those files/folders wherever you want to.

This article has been dead for over six months. Start a new discussion instead.