• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

and yet another recursive problem

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i triedx another recursion exercise... but unfortunately... the program runs.. until the end of the inputs... it displays nullpointerexception... its the first time i've encountered this and i just want to know... because i don't know how to handle a nullPointer exception... thanks in advance!!!
here it is...
 
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have not figured out everything you are doing in this program, but I can tell you what your error is.

You have the statement



This code allocates space for an array of a number of class3 objects, but it does not put any objects in that array. Therefore, every one of those slots in class3 is equal to null. When you get to the statement in your merge method that attempts to do a compare on two elements of class3, neither of them have values, and attempting to call the method compareTo() on one of them fails.

If you mean to copy class1 and class2 elements into class3, you need other statements to do that.

Now, about null pointer exceptions -- they mean very much what they sound like. When you dereference an object reference (which is the technical term for putting a period after it and referring to one of its properties, variables, or methods), that object reference must exist. If it is equal to null, then the runtime has no idea what to do with that reference, and throws a null pointer exception. If you have not trapped null pointer exceptions in an enclosing scope, the program ends.

rc
 
Momo Sawada
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i think i get what you're saying.... so i will try it... A great many thanks!!!
 
Did you ever grow anything in the garden of your mind? - Fred Rogers. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic