• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

and yet another recursive problem  RSS feed

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
i think i get what you're saying.... so i will try it... A great many thanks!!!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!