| | |
problem with accessing code after method call
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,818
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,818
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,574
Reputation:
Solved Threads: 199
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 |
-xlint add android api applet application applications array arrays automation bank bi binary blackberry bluetooth chat class client code compile compiler component database development digit eclipse equation error event fractal freeze functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide idea image infinite input int integer j2me java javame javaprojects jetbrains jni jpanel jtable julia learningresources linux list login loop main map method methods mobile myregfun netbeans newbie nonstatic notdisplaying pearl problem program programming project qt recursion scanner screen scrollbar server set sms sort sorting spamblocker sql sqlserver string superclass swing system text-file thread threads tree variablebinding windows xor






