• 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
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

the output is getting printed but after this, runtime error is showing.

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
code:

the output is getting printed but after, this runtime error is showing.

I am unable to find the mistake.
 
Saloon Keeper
Posts: 7488
171
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why does line 34 exist? The while loop terminates if "curr.right==null" is false - so there would be no need to check exactly that right after the loop.

I advise to use curly braces with else statements, especially if the if statements has them as well. Otherwise it's confusing to read. I'm pretty sure lines 31 and 32 go together - but currently they do not. In fact, line 32 is executed after you set "curr=null;" - where it is sure to throw just the exception you're witnessing.
 
Aditya Lath
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Line 34 is there to fulfill the purpose of iteration here. As the stack will only be saving left subtree, this is how right subtree is coming into consideration. The while loop is solely used here for the right subtree.

I have made changes in the code as you suggested in the second paragraph but the error remains the same.



 
Sheriff
Posts: 27451
88
Eclipse IDE Firefox Browser MySQL Database
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You've got this while-loop:



It's possible that at some point you set curr=null inside the loop. You've got code which can do that, anyway. If that happens then the next thing that happens is, control goes back to the while-statement to see if the loop is finished or not.

Can I leave it to you to figure out why that's a problem?
 
Aditya Lath
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much man(Paul clapham), issue resolved.
 
Paul Clapham
Sheriff
Posts: 27451
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good to hear it!
 
rubbery bacon. crispy tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic