I am a bit inexperienced in programming and may therefore be foolish. But I have a problem in the following method:
import java.util.Set;
public class Launcher
{
public static void printEntries(ReadableMap<String, Integer> a)
{
Set<String> b = a.keysAsSet();
try
{
for(String i : b)
{
if(i != null)
{
getOrThrow(i);
}
System.out.println(i + ": " + getOrThrow(i));
}
}
catch(UnknownKeyException z)
{
throw new UnknownKeyException();
System.out.println("Eine UnknownKeyException ist aufgetreten.");
}
}
}
The method getOrThrow(String) is undefined for the type Launcher.
Here are some code snippets that might be helpful:
public interface ReadableMap<K, V> {
public abstract V getOrThrow(K key) throws UnknownKeyException;
}
and
public abstract class AbstractReadableMap<K, V> implements ReadableMap<K, V>
{
protected Entry<K, V>[] entries;
public V getOrThrow(K k) throws UnknownKeyException
{
for(Entry<K, V> i : entries)
{
if(i.getValue() != null && i.getKey().equals(k))
{
return i.getValue();
}
}
throw new UnknownKeyException();
}
}
Why is that and how can I fix it?
I am very grateful for any kind of help. Thank you in advance!
The call to getOrThrow(i)
here is implicitly Launcher.getOrThrow(i)
- in other words, it is calling a method belonging to class Launcher. You may want to call a.getOrThrow(i)
instead, since a
is of a type that does implement that method, ReadableMap
.