This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Java in General and the fly likes sorry... my previous mail got posted halfway...completing now Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "sorry... my previous mail got posted halfway...completing now" Watch "sorry... my previous mail got posted halfway...completing now" New topic
Author

sorry... my previous mail got posted halfway...completing now

Deb Pati
Greenhorn

Joined: Aug 04, 2006
Posts: 4
Hi all,

I have the following code segment: It has a "Manager" class with an inner class called "KeyValue". Another class named "Caller" tries to instantiate an object of type Manager. The Eclipse debugger gave a ClassNotFoundException at line number 19. So looks like there is a
runtime problem in finding and loading the class dynamically as it is a generic type. Please, please help me soon.

1. public class Manager{

//*** inner class ***
2. public class KeyValue {
3. protected Object element;
4. protected Object value;
5. public KeyValue(Object element, Object value) {
6. this.element = element;
7. this.value = value;
8. }
9. }
//***** inner class end *****

10. protected List<KeyValue> cache;
11. int direction;

12. public Manager(List<KeyValue> cache,int direction){
13. this.cache = cache;
14. this.direction = direction;

15. }
16. }
----------------------------------
17. public class Caller{

18. public void callerMethod{
19. List<KeyValue> mycache = new ArrayList<KeyValue>();
20. int Direction = 3;
21. Manager m = new Manager(mycache, 3);
22. }
23.}
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60077
    
  65

You could have edited you first post if you didn't like the way it came out.

Please edit this one to give it a more appropriate subject. Alos, as this is not an advanced Java question, I have moved it to the intermediate forum.
[ August 04, 2006: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

Using linenumbers to let us find the errornous line is a good idea, but it breaks code-indentation.
A better method is this:

It's better readable, and might be transfered to an editor by cut'n'paste.
Since KeyValue is an inner class (why?), its name is Manager.KeyValue

[ August 04, 2006: Message edited by: Stefan Wagner ]

http://home.arcor.de/hirnstrom/bewerbung
manuel aldana
Ranch Hand

Joined: Dec 29, 2005
Posts: 308
and especially with line numbering copy/paste gets quite time consuming.

but your code example did not need it

i am wondering that you get an exception during runtime because your code should not have even compiled because inner classes are only visible in classes where they got defined.

and you're defining List<KeyValue>.


aldana software engineering blog & .more
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

Yes. And callerMethod needs braces:

Allways post the code in question, not something which is similar, but untested.
Deb Pati
Greenhorn

Joined: Aug 04, 2006
Posts: 4
Thanks a lot guys ! I had indented my first msg., but
it did not preserve it. Should I use spaces or tabs to
get the lines indented? Also, I don't know how I could
have got back to my first incomplete mail and have it
completed.

Now, to the technical answers: I wanted to use the benefit
of inner class in the rest of my actual code....hence I had
declared KeyValue that way. I do need it to be visible in
the Calling class and I know it can be done. I will try the
suggestion of <Manager.KeyValue> However, I recently talked
to another friend who gave a good suggestion too. It is
to have the contructor of Manager class be like:

public Manager(int direction){
this.direction = direction;
Deb Pati
Greenhorn

Joined: Aug 04, 2006
Posts: 4
Sorry guys,

made the same mistake again ! Hit the tab key or something and
my reply got posted half way. Please let me know how I could have
gotten back to my half edited reply.

But, for now let me continue with what my friend suggested:

Write the constructor of Manager as:

public Manager(int direction){
this.direction = direction;
cache = new ArrayList<KeyValue>();
}

Then in the class Caller:

public void callerMethod(){
int direction = 3;
Manager m = new Manager(direction);

This way, the constructor of Manager will create an instance
of ArrayList<KeyValue> within the callerMethod.

BTW, the class Manager and Caller are in 2 different packages.

Thanks for the life(job) saver replies. I will give a
try to the posted suggestion and my friends and hopefully one
of them will work.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

Originally posted by Deb Pati:
Thanks a lot guys ! I had indented my first msg., but
it did not preserve it. Should I use spaces or tabs to
get the lines indented? Also, I don't know how I could
have got back to my first incomplete mail and have it
completed.

1.
To indent your post, you may use tabs or spaces.
I recommend spaces.
To make the indentation visible, there are two main ways, to reach the goal:
In the edit box:
a) hit the 'code'-button in the 'Instant UBB Code'-Section.
Type your code.*
Hit the button again.

b) Type your code, or paste it from your editor.
Mark the code.
Hit the code Button.

(Hit the road, Jack, won't you come back no more, no more...)

*) This way, you will not be able to insert tabs, because your tab-key will push the focus out of the editfield.

2. To edit a posting, look at the top of your entry.
There is a small icon: Paper and pencil. Hit it!
Hit it with your rythm stick - hit it.
In doubt: take your mouse.

3. From the code we have seen so far, your friend is right.
Since the Caller doesn't use mycache, he needn't know about it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sorry... my previous mail got posted halfway...completing now
 
Similar Threads
inner class - ClassNotFoundException
stuck up in the problem
Cannot find bean in request scope
Object Caching?
compile-time type checking