Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

please explain this runtime exception..

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..
pl look at this code:

the code gives NullPointerException on lines 8 and 17
whether line 7 is commented or not
when the line is commented, what is the class of nI? Object,I guess. then why is it not displaying the class in line 8 and throwing an exception instead?
when line 7 is not commented, the test in line 9 fails ,and "no" should be printed..
could somebody explain please?
thanks in advance
Ramani.
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<The code gives NullPointerException on lines 8 and 17 <br /> whether line 7 is commented or not when the line is commented, what is the class of nI? Object,I guess. then why is it not displaying the class in line 8 and throwing an exception instead?>
Whether line 7 is commented or not the class level variables are initialised to null,in your program commenting or uncommenting line 7 has absolutely no effect and in line 8 you are calling the method getClass on null object and at this point of time the program will throw an exception and it won't even go into the if..else part,comment line 8 and then the program will print no.
Surya
 
ramani2020
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yup! I couldnt be more dumb
I guess I shd start from scrap 'gain...
thanks Surya..
Ramani.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic