sorry... my previous mail got posted halfway...completing now
Deb Pati
Greenhorn
Joined: Aug 04, 2006
Posts: 4
posted
0
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;
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.}
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 ]
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.
Allways post the code in question, not something which is similar, but untested.
Deb Pati
Greenhorn
Joined: Aug 04, 2006
Posts: 4
posted
0
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
posted
0
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.
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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: sorry... my previous mail got posted halfway...completing now