• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.}
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. And callerMethod needs braces:

Allways post the code in question, not something which is similar, but untested.
 
Deb Pati
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Attractive, successful people love this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic