Results 1 to 5 of 5
- 01-19-2013, 12:46 PM #1
Member
- Join Date
- Jan 2013
- Posts
- 3
- Rep Power
- 0
Problems with using other classes methods/instances
Hi, I'm new to Java, and I've got a problem with it.
I'm writing a class that reverts the content of a stack;
In the folder there are: ReverseStackUsingTwoStacks.java
ArrayListStack.java ==> Interface that wraps ArrayList, making an ArrayList instance a Stack
ArrayListStack.class
When I try to compile the code you're reading under my post, the compiler says
"error: cannot find symbol
ArrayListStack temp2 = new ArrayListStack<Integer>();
^
symbol: class ArrayListStack
location: class ReverseStackUsingTwoStacks"
Here is the code:
PS do not focus on single programming error, my problem is that even when creating an instance of ArrayListStack, the compiler says he do not find the symbol etc etc.Java Code:import static java.lang.System.*; import java.util.Scanner; public class ReverseStackUsingTwoStacks { public static void main(String[] args) { Scanner in = new Scanner(System.in); ArrayListStack<Integer> stack = new ArrayListStack<Integer>(); while (in.hasNextInt()) { stack.push(in.nextInt()); } StackInverter(stack); while (!stack.isEmpty()) out.println(stack.pop()); } public static void StackInverter(ArrayListStack<Integer> stack) { ArrayListStack temp1 = new ArrayListStack<Integer>(); ArrayListStack temp2 = new ArrayListStack<Integer>(); while (!stack.isEmpty()) { int element = stack.pop(); temp1.push(element); } while (!temp1.isEmpty()) { int element = temp1.pop(); temp2.push(element); } while (!temp2.isEmpty()) { int element = temp2.pop(); stack.push(element); } } }
Thanks.Last edited by laMonaca; 01-19-2013 at 12:54 PM. Reason: Wrapped code into code tags
- 01-19-2013, 12:51 PM #2
Senior Member
- Join Date
- Jan 2011
- Location
- Belgrade, Serbia
- Posts
- 227
- Rep Power
- 3
Re: Problems with using other classes methods/instances
please wrap your code in code tags.
- 01-19-2013, 12:55 PM #3
Member
- Join Date
- Jan 2013
- Posts
- 3
- Rep Power
- 0
Re: Problems with using other classes methods/instances
Done, sorry, I've never even posted a piece of code before.
- 01-19-2013, 01:48 PM #4
Member
- Join Date
- Jan 2013
- Posts
- 4
- Rep Power
- 0
Re: Problems with using other classes methods/instances
It seems from the pasted code that you forgot to import the class for ArrayListStack. Does it keep failing to compile when you do import it?
- 01-19-2013, 01:57 PM #5
Member
- Join Date
- Jan 2013
- Posts
- 3
- Rep Power
- 0
Re: Problems with using other classes methods/instances
But, I knew that a class in the same directory has not to be imported, it is not in a package...
There's the interface:
Java Code:import java.util.ArrayList; public class ArrayListStack<T> { private ArrayList<T> a; public ArrayListStack() { a = new ArrayList<T>(); } public int size() { return a.size(); } public boolean isEmpty() { return a.isEmpty(); } public void push(T element) { a.add(element); } public T top() { if (isEmpty()) throw new java.util.NoSuchElementException(); return a.get(a.size()-1); } public T pop() { if (isEmpty()) throw new java.util.NoSuchElementException(); return a.remove(a.size()-1); } }
!!!!SOLVED!!!!
I just added the whole C: to Classpath system variable, now it compiles. Sorry for the disturb. Thanks.Last edited by laMonaca; 01-19-2013 at 02:00 PM.
Similar Threads
-
Help with instances of classes and variables!
By lifedistroy in forum New To JavaReplies: 5Last Post: 12-24-2012, 07:15 AM -
How to get a better understanding of Objects/Classes/Instances
By FAkamo in forum New To JavaReplies: 2Last Post: 01-22-2012, 11:50 PM -
Creating new instances in a loop problems
By monkeyhead in forum New To JavaReplies: 6Last Post: 11-18-2011, 09:14 PM -
Passing information between instances of classes
By Isty in forum New To JavaReplies: 6Last Post: 10-02-2011, 05:55 PM -
Deleting instances of classes from a list
By Gmurph03 in forum New To JavaReplies: 8Last Post: 11-27-2009, 11:41 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks