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

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

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

Recommended Answers

All 6 Replies

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

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

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.

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");
}

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.

myClass2 class2 =new myClass2(class4);
//other instantiations 
myClass4 class4=new myClass2(class1, class2, class3);

and

//other instantiations 
myClass4 class4=new myClass2(class1, class2, class3)
myClass2 class2 =new myClass2(class4);

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.

myClass2 class2 =new myClass2(class4);
//other instantiations 
myClass4 class4=new myClass2(class1, class2, class3);

and

//other instantiations 
myClass4 class4=new myClass2(class1, class2, class3)
myClass2 class2 =new myClass2(class4);

You're right, that won't work.

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:

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

I dont get what you mean by

class4.setclass2(class2)

Is setclass a reserved method or something or is there something I didnt quite understand

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:

public class ExampleClass{
     String myString;
     public void setString(String otherString){
          myString = otherString;
     }
}

thanks for the replies...got it working now

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.