问题
In my code, I have a nestted class that holds an object and an integer. This is to mark the beginning and end locations for a sublist method.
The code executes to the point that the object and integer have established values. I've verified this in the debugger.
The next line then calls ListLoc<E> startNode= new ListLoc<E>(start, startElement);
and that is what trips the exception.
The class is already defined as
private class ListLoc<E>{
public Chunk<E> node;
public int index;
/* This object is created to hold a chunk and index location. Two
* objects will be created for the start and end locations for
* creating a sublist
*/
public ListLoc(Chunk<E> node, int index){
this.node= node;
this.index= index;
}
}
The strange thing is this portion of the code was executing fine before I replaced the local startNode with a global variable. That idea didn't work out, so I changed the variable back, and this exception cropped up.
I have made no changes to the class path or executions. The only time this crops up is in the debugger
EDIT: added stack trace
ClassNotFoundException(Throwable).(String, Throwable) line: 217
ClassNotFoundException(Exception).(String, Throwable) line: not available
ClassNotFoundException.(String) line: not available
URLClassLoader$1.run() line: not available
AccessController.doPrivileged(PrivilegedExceptionAction, AccessControlContext) line: not available [native method]
Launcher$ExtClassLoader(URLClassLoader).findClass(String) line: not available
Launcher$ExtClassLoader.findClass(String) line: not available
Launcher$ExtClassLoader(ClassLoader).loadClass(String, boolean) line: not available
Launcher$AppClassLoader(ClassLoader).loadClass(String, boolean) line: not available
Launcher$AppClassLoader.loadClass(String, boolean) line: not available
Launcher$AppClassLoader(ClassLoader).loadClass(String) line: not available
From what it looks to me, its the classLoader that triggers the exception.
回答1:
It would help if you could clarify what the exception is, however, I am guessing that you are getting a ClassNotFound for E.
It looks like your professor has not clarified the concept of Generics yet. I would recommend looking over what a generic data structure is. THe advice I would give is to look for why E is not defined and why you are trying to create a list of them.
I think that the following link might help to clarify the syntax and the concepts behind them: http://download.oracle.com/javase/tutorial/extra/generics/index.html
Particularly the following section: http://download.oracle.com/javase/tutorial/extra/generics/simple.html
来源:https://stackoverflow.com/questions/3991466/debugging-a-classnotfoundexception