| | |
problem with accessing code after method call
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Oct 2007
Posts: 280
Reputation:
Solved Threads: 19
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
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
I hope this can put my point across. Any help is highly appreciated
java Syntax (Toggle Plain Text)
if(//some condition){ //some code myMethod(//some variables); //some code/*not executed*/ }
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)
public void myMethod(//some variables) { //some code here, basically initializing buffer streams try { //a new file output stream is created here } catch(IOException e ){ } //some jpeg encoding code try { // jpeg encoder and closing the file stream } catch (IOException e){ } }
I hope this can put my point across. Any help is highly appreciated
•
•
Join Date: Jan 2008
Posts: 3,829
Reputation:
Solved Threads: 501
•
•
•
•
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)
if(//some condition){ //some code myMethod(//some variables); //some code/*not executed*/ }
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)
public void myMethod(//some variables) { //some code here, basically initializing buffer streams try { //a new file output stream is created here } catch(IOException e ){ } //some jpeg encoding code try { // jpeg encoder and closing the file stream } catch (IOException e){ } }
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)
public void myMethod(//some variables) { //some code here, basically initializing buffer streams System.out.println ("Before first try"); try { //a new file output stream is created here System.out.println ("In first try"); } catch(IOException e ){ System.out.println ("In first catch"); } //some jpeg encoding code System.out.println ("Between first and second try/catch"); try { // jpeg encoder and closing the file stream System.out.println ("In second try"); } catch (IOException e){ System.out.println ("In second catch"); } System.out.println ("Made it to end of myMethod"); }
•
•
Join Date: Oct 2007
Posts: 280
Reputation:
Solved Threads: 19
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. and
java Syntax (Toggle Plain Text)
myClass2 class2 =new myClass2(class4); //other instantiations myClass4 class4=new myClass2(class1, class2, class3);
java Syntax (Toggle Plain Text)
//other instantiations myClass4 class4=new myClass2(class1, class2, class3) myClass2 class2 =new myClass2(class4);
Last edited by joshmo; Jun 26th, 2009 at 6:14 am.
•
•
Join Date: Jan 2008
Posts: 3,829
Reputation:
Solved Threads: 501
•
•
•
•
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.andjava Syntax (Toggle Plain Text)
myClass2 class2 =new myClass2(class4); //other instantiations myClass4 class4=new myClass2(class1, class2, class3);
java Syntax (Toggle Plain Text)
//other instantiations myClass4 class4=new myClass2(class1, class2, class3) myClass2 class2 =new myClass2(class4);
You're right, that won't work.
JAVA Syntax (Toggle Plain Text)
myClass4 class4=new myClass2(class1, class2, class3) 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)
myClass4 class4=new myClass2(class1, class3) myClass2 class2 =new myClass2(class4); class4.setclass2 (class2);
•
•
Join Date: Oct 2007
Posts: 280
Reputation:
Solved Threads: 19
•
•
•
•
JAVA Syntax (Toggle Plain Text)
myClass4 class4=new myClass2(class1, class3) myClass2 class2 =new myClass2(class4); class4.setclass2 (class2);
Java Syntax (Toggle Plain Text)
class4.setclass2(class2)
•
•
Join Date: Sep 2008
Posts: 1,610
Reputation:
Solved Threads: 205
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)
public class ExampleClass{ String myString; public void setString(String otherString){ myString = otherString; } }
Out.
![]() |
Similar Threads
- trouble with method call (Java)
- (problem) Accessing Control of TabPage (C#)
- Problem creating factorize method for generating Prime Numbers (Java)
- On method call save its name (Python)
- Problem accessing Windows Share (Networking Hardware Configuration)
- Urgent...Having problem with the following HTML code in IE7 (HTML and CSS)
- Problem accessing various site (Viruses, Spyware and other Nasties)
- Non-static method can't be referenced from a static context (Java)
Other Threads in the Java Forum
| Thread Tools | Search this Thread |
2dgraphics account android api apple applet application array arrays automation banking binary binarytree bluetooth chat chatprogramusingobjects class classes client code component data database derby design draw eclipse encryption error event exception fractal game givemetehcodez graphics gui html ide if_statement image inheritance input integer interface j2me java javadesktopapplications javaprojects jlabel jni jpanel jtextfield julia linux list loop map method methods midlethttpconnection mobile monitoring netbeans newbie nullpointerexception open-source oracle print printing problem program programming project property recursion reference ria scanner screen search server set size sms sort sourcelabs splash sql static stop string swing testautomation threads time tree ui unicode validation windows






