problem with accessing code after method call

Thread Solved

Join Date: Oct 2007
Posts: 280
Reputation: joshmo is an unknown quantity at this point 
Solved Threads: 19
joshmo joshmo is offline Offline
Posting Whiz in Training

problem with accessing code after method call

 
0
  #1
Jun 25th, 2009
I have a code that calls a method, but after this call, any code after it is not executed....here is the method call skeleton
  1.  
  2. if(//some condition){
  3. //some code
  4. myMethod(//some variables);
  5. //some code/*not executed*/
  6. }

the calling is done well but the code stays in that method i.e code following the method call is not executed. I dont know if this maybe due to the method being called because there method does not return anything. below is a skeleton of the method
  1. public void myMethod(//some variables)
  2. {
  3. //some code here, basically initializing buffer streams
  4. try
  5. {
  6. //a new file output stream is created here
  7. }
  8.  
  9. catch(IOException e ){
  10. }
  11.  
  12. //some jpeg encoding code
  13.  
  14. try
  15. {
  16. // jpeg encoder and closing the file stream
  17. }
  18.  
  19. catch (IOException e){
  20.  
  21. }
  22. }

I hope this can put my point across. Any help is highly appreciated
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,818
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: problem with accessing code after method call

 
0
  #2
Jun 25th, 2009
Originally Posted by joshmo View Post
I have a code that calls a method, but after this call, any code after it is not executed....here is the method call skeleton
  1.  
  2. if(//some condition){
  3. //some code
  4. myMethod(//some variables);
  5. //some code/*not executed*/
  6. }

the calling is done well but the code stays in that method i.e code following the method call is not executed. I dont know if this maybe due to the method being called because there method does not return anything. below is a skeleton of the method
  1. public void myMethod(//some variables)
  2. {
  3. //some code here, basically initializing buffer streams
  4. try
  5. {
  6. //a new file output stream is created here
  7. }
  8.  
  9. catch(IOException e ){
  10. }
  11.  
  12. //some jpeg encoding code
  13.  
  14. try
  15. {
  16. // jpeg encoder and closing the file stream
  17. }
  18.  
  19. catch (IOException e){
  20.  
  21. }
  22. }

I hope this can put my point across. Any help is highly appreciated

You could have an infinite loop. You could never return from your function. You could have some uncaught exception that is crashing the program. You need to put in some debugging to see how far you make it. Breakpoints would be better, but since I can't put them here, I'll use System.out.println statements. See how far you get by what displays. Again, breakpoints are much faster, with nothing to remember to delete.

  1. public void myMethod(//some variables)
  2. {
  3. //some code here, basically initializing buffer streams
  4.  
  5. System.out.println ("Before first try");
  6.  
  7. try
  8. {
  9. //a new file output stream is created here
  10. System.out.println ("In first try");
  11. }
  12.  
  13. catch(IOException e ){
  14. System.out.println ("In first catch");
  15. }
  16.  
  17. //some jpeg encoding code
  18. System.out.println ("Between first and second try/catch");
  19.  
  20. try
  21. {
  22. // jpeg encoder and closing the file stream
  23. System.out.println ("In second try");
  24. }
  25.  
  26. catch (IOException e){
  27. System.out.println ("In second catch");
  28. }
  29.  
  30. System.out.println ("Made it to end of myMethod");
  31. }
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 280
Reputation: joshmo is an unknown quantity at this point 
Solved Threads: 19
joshmo joshmo is offline Offline
Posting Whiz in Training

Re: problem with accessing code after method call

 
0
  #3
Jun 26th, 2009
thanks..managed to debug the code. However, I have another problem with using class objects. I have 2 classes, which need objects if each other..however, I cant seem to find a way of making this work...below is an example, and some of the obvious ideas that cannot work.
  1.  
  2. myClass2 class2 =new myClass2(class4);
  3. //other instantiations
  4. myClass4 class4=new myClass2(class1, class2, class3);
and
  1. //other instantiations
  2. myClass4 class4=new myClass2(class1, class2, class3)
  3. myClass2 class2 =new myClass2(class4);
Last edited by joshmo; Jun 26th, 2009 at 6:14 am.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,818
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: problem with accessing code after method call

 
0
  #4
Jun 26th, 2009
Originally Posted by joshmo View Post
thanks..managed to debug the code. However, I have another problem with using class objects. I have 2 classes, which need objects if each other..however, I cant seem to find a way of making this work...below is an example, and some of the obvious ideas that cannot work.
  1.  
  2. myClass2 class2 =new myClass2(class4);
  3. //other instantiations
  4. myClass4 class4=new myClass2(class1, class2, class3);
and
  1. //other instantiations
  2. myClass4 class4=new myClass2(class1, class2, class3)
  3. myClass2 class2 =new myClass2(class4);

You're right, that won't work.

  1. myClass4 class4=new myClass2(class1, class2, class3)
  2. myClass2 class2 =new myClass2(class4);

class2 is created in line 2, so it doesn't exist yet in line 1, so you can't pass it in line 1. So don't pass it. You can set it later, after both objects exist:


  1. myClass4 class4=new myClass2(class1, class3)
  2. myClass2 class2 =new myClass2(class4);
  3. class4.setclass2 (class2);
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 280
Reputation: joshmo is an unknown quantity at this point 
Solved Threads: 19
joshmo joshmo is offline Offline
Posting Whiz in Training

Re: problem with accessing code after method call

 
0
  #5
Jun 26th, 2009
Originally Posted by VernonDozier View Post
  1. myClass4 class4=new myClass2(class1, class3)
  2. myClass2 class2 =new myClass2(class4);
  3. class4.setclass2 (class2);
I dont get what you mean by
  1. class4.setclass2(class2)
Is setclass a reserved method or something or is there something I didnt quite understand
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,574
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 199
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

Re: problem with accessing code after method call

 
0
  #6
Jun 26th, 2009
No, it is not a "reserved method". He means for you to create the method, so that after your Object is created, you can use that method to pass it to the other class. A small example:

  1. public class ExampleClass{
  2. String myString;
  3. public void setString(String otherString){
  4. myString = otherString;
  5. }
  6. }
Out.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 280
Reputation: joshmo is an unknown quantity at this point 
Solved Threads: 19
joshmo joshmo is offline Offline
Posting Whiz in Training

Re: problem with accessing code after method call

 
0
  #7
Jun 27th, 2009
thanks for the replies...got it working now
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC