0
votes

I'm using scala v2.10.2; eclipse with scala plugin v3.0.1; The full error message is:

error while loading Vector$1, class file 'C:\Program Files\Java\jre7\lib\rt.jar(java/util/Vector$1.class)' is broken (class java.util.NoSuchElementException/key not found: E)

It occurs when attempting to extending java.util.Stack

import java.util.Stack
class MyStack[T] extends Stack[T]{}

It's worth noting that java.util.Stack is a subclass of java.util.Vector.

2

2 Answers

2
votes

java.util.Stack extends the essentially deprecated java.util.Vector, and thus is also essentially deprecated (they're not actually deprecated, but the docs always recommends using newer alternatives if you're running a newer version of Java). The javadoc for Stack recommends using the java.util.Deque interface instead:

A more complete and consistent set of LIFO stack operations is provided by the Deque interface and its implementations, which should be used in preference to this class. For example: Deque<Integer> stack = new ArrayDeque<Integer>();

Using the Deque interface and java.util.ArrayDeque will probably solve your problem since—referring to pretzels1337's answer—this seems to be a Vector-specific bug.

2
votes

eThis same issue may be part of a larger bug report: https://issues.scala-lang.org/browse/SI-7455

The report claims fixed in Scala 2.10.3-RC1, Scala 2.11.0-M6

I'm waiting for the next stable scala IDE update before verifying fixed (lazy I know) but a simple work around in the mean time is to simply change the class definitions to extend scala.collection.mutable.Stack instead.

-- Most people running into this issue are trying to use swing; for you I can only recommend trying one of the fixed builds of scala.