943,600 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 558
  • Java RSS
Jun 25th, 2009
0

problem with accessing code after method call

Expand 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
java Syntax (Toggle Plain Text)
  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
java Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 19
Solved Threads: 20
Posting Whiz in Training
joshmo is offline Offline
280 posts
since Oct 2007
Jun 25th, 2009
0

Re: problem with accessing code after method call

Click to Expand / Collapse  Quote originally posted by joshmo ...
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
java Syntax (Toggle Plain Text)
  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
java Syntax (Toggle Plain Text)
  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.

java Syntax (Toggle Plain Text)
  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. }
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,372 posts
since Jan 2008
Jun 26th, 2009
0

Re: problem with accessing code after method call

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.
java Syntax (Toggle Plain Text)
  1.  
  2. myClass2 class2 =new myClass2(class4);
  3. //other instantiations
  4. myClass4 class4=new myClass2(class1, class2, class3);
and
java Syntax (Toggle Plain Text)
  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.
Reputation Points: 19
Solved Threads: 20
Posting Whiz in Training
joshmo is offline Offline
280 posts
since Oct 2007
Jun 26th, 2009
0

Re: problem with accessing code after method call

Click to Expand / Collapse  Quote originally posted by joshmo ...
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.
java Syntax (Toggle Plain Text)
  1.  
  2. myClass2 class2 =new myClass2(class4);
  3. //other instantiations
  4. myClass4 class4=new myClass2(class1, class2, class3);
and
java Syntax (Toggle Plain Text)
  1. //other instantiations
  2. myClass4 class4=new myClass2(class1, class2, class3)
  3. myClass2 class2 =new myClass2(class4);

You're right, that won't work.

JAVA Syntax (Toggle Plain Text)
  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:


JAVA Syntax (Toggle Plain Text)
  1. myClass4 class4=new myClass2(class1, class3)
  2. myClass2 class2 =new myClass2(class4);
  3. class4.setclass2 (class2);
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,372 posts
since Jan 2008
Jun 26th, 2009
0

Re: problem with accessing code after method call

JAVA Syntax (Toggle Plain Text)
  1. myClass4 class4=new myClass2(class1, class3)
  2. myClass2 class2 =new myClass2(class4);
  3. class4.setclass2 (class2);
I dont get what you mean by
Java Syntax (Toggle Plain Text)
  1. class4.setclass2(class2)
Is setclass a reserved method or something or is there something I didnt quite understand
Reputation Points: 19
Solved Threads: 20
Posting Whiz in Training
joshmo is offline Offline
280 posts
since Oct 2007
Jun 26th, 2009
0

Re: problem with accessing code after method call

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:

Java Syntax (Toggle Plain Text)
  1. public class ExampleClass{
  2. String myString;
  3. public void setString(String otherString){
  4. myString = otherString;
  5. }
  6. }
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008
Jun 27th, 2009
0

Re: problem with accessing code after method call

thanks for the replies...got it working now
Reputation Points: 19
Solved Threads: 20
Posting Whiz in Training
joshmo is offline Offline
280 posts
since Oct 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Heap sort
Next Thread in Java Forum Timeline: repaint





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC