Hello, I'm a biologist trying to do some bioinformatics, so new to Java and new to this forum. I've searched all over the forum for previous threads on this topic, but can't find an answer that has helped me. Apologies if I've missed something already posted that may help solve my problem. I'm currently trying to write a method that will return a boolean true or false. I am getting an error though saying 'missing return statement'. I can't for the life of me work out what the issue is. I've tried changing the braces, rearranging the remove statements in and around the braces, but no luck.

public boolean FailurePoint(int selectedNodes[], CyNetwork network)  {
//error is here 'missing return statement'

            int kids[] = network.getAdjacentEdgeIndicesArray(selectedNodes[0], false, true, true);
            int[] ChildNode = new int[kids.length];



            for (int c = 0; c < ChildNode.length; c++) {

                int node = network.getEdgeSourceIndex(kids[c]);
                if (node == selectedNodes[0]) {
                    node = network.getEdgeTargetIndex(kids[c]);
                }

                ChildNode[c] = node;
            }
            Vector<Integer> cnodes = new Vector<Integer>();

            for (int c = 0; c < ChildNode.length; c++) {

                int node = ChildNode[c];

                if (!cnodes.contains(node)) {
                    cnodes.add(node); 



            for (int i = 1; i < cnodes.size(); i++) {

                boolean isConnected = hasPath(cnodes.elementAt(0), cnodes.elementAt(i), selectedNodes[0], network);


                boolean OneKid = false;
                if (cnodes.size() < 2) {
                    OneKid = true;
                }
                 else {
                    OneKid = false;
                }

                boolean FailurePoint;
                if ((isConnected == true) || (OneKid == true)) {
                    FailurePoint = false;
                    return false;
  
                } 
				else {
                    FailurePoint = true;
                    return true;                  
                    
                }        
			return FailurePoint;   
        }
         
    }
}

I have tried writing the last piece as follows but get the exact same error:

if ((isConnected == true) || (OneKid == true)) {
                    
                    return false;
                    
                } else {
                    
                    return true;               
                    
                }        
    
        }
       
    }
}

I know all the braces don't tally up here, but there are other methods and class above, this. I didn't think it necessary to clog up space with all that code too.
I'll be grateful for any help, thanks in advance :icon_smile:

Recommended Answers

All 6 Replies

Looks to me like the problem is the open curly at line 24:

if (!cnodes.contains(node)) {
                    cnodes.add(node);

or rather the lack of a close brace.
This means that if the condition is true, you skip all the way down to the end, past your return statements.

Oops, Sorry, my mistake. I cut out some commented out notes near there before posting and seem to have deleted the curlies too...they are there in the original as follows:

public boolean FailurePoint(int selectedNodes[], CyNetwork network)  {


            int kids[] = network.getAdjacentEdgeIndicesArray(selectedNodes[0], false, true, true);
            int[] ChildNode = new int[kids.length];



            for (int c = 0; c < ChildNode.length; c++) {

                int node = network.getEdgeSourceIndex(kids[c]);
                if (node == selectedNodes[0]) {
                    node = network.getEdgeTargetIndex(kids[c]);
                }

                ChildNode[c] = node;
            }
            Vector<Integer> cnodes = new Vector<Integer>();

            for (int c = 0; c < ChildNode.length; c++) {

                int node = ChildNode[c];

                if (!cnodes.contains(node)) {
                    cnodes.add(node); 

				}
			}

            for (int i = 1; i < cnodes.size(); i++) {

                boolean isConnected = hasPath(cnodes.elementAt(0), cnodes.elementAt(i), selectedNodes[0], network);


                boolean OneKid = false;
                if (cnodes.size() < 2) {
                    OneKid = true;
                }
                boolean FailurePoint;
                if ((isConnected == true) || (OneKid == true)) {
                    FailurePoint = false;
                    return false;
  
                } 
				else {
                    FailurePoint = true;
                    return true;                  
                    
                }        
			return FailurePoint;   
        }
         
    }
}
public boolean FailurePoint(int selectedNodes[], CyNetwork network) {

        int kids[] = network.getAdjacentEdgeIndicesArray(selectedNodes[0], false, true, true);
        int[] ChildNode = new int[kids.length];
        for (int c = 0; c < ChildNode.length; c++) {
            int node = network.getEdgeSourceIndex(kids[c]);
            if (node == selectedNodes[0]) {
                node = network.getEdgeTargetIndex(kids[c]);
            }
            ChildNode[c] = node;
        }

        Vector<Integer> cnodes = new Vector<Integer>();
        for (int c = 0; c < ChildNode.length; c++) {
            int node = ChildNode[c];
            if (!cnodes.contains(node)) {
                cnodes.add(node);
            }
        }
        
        boolean FailurePoint;
        for (int i = 1; i < cnodes.size(); i++) {
            boolean isConnected = hasPath(cnodes.elementAt(0), cnodes.elementAt(i), selectedNodes[0], network);
            boolean OneKid = false;
            if (cnodes.size() < 2) {
                OneKid = true;
            }
            //boolean FailurePoint;
            if ((isConnected == true) || (OneKid == true)) {
                FailurePoint = false;
                //return false;
            } else {
                FailurePoint = true;
                //return true;
            }
        }
        return FailurePoint;
    }

Thanks for replying. If I do it that way, I lose the missing return statement error, but instead get an error saying variable FailurePoint has not been initialized

Initialize the variable to a default value, whichever would make more sense as a default for your usage.

Wow, thank you so much, sorted now! No more horrible red error marks in my code
Cheers guys :icon_smile:

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.