Stack Exchange
I keep on getting one error regarding connectNode method
I have a node class defined as below, but I keep on getting the error in Eclipse 

void is an invalid type for the variable connectNode

Please explain why?
 class Node{

    char label;

    boolean visited = false;

    public Node (char l){
        this.label=l;
    }
    public String toString() {
        return Character.toString(label);
    }
 }

I have defined ArrayList as below:
ArrayList<Node> nodes = new ArrayList<Node>();

I'm trying to use the following method to print the values of Start and End index
public void connectNode(Node start,Node end){
   int startIndex=nodes.indexOf(start);
   int endIndex=nodes.indexOf(end);

   System.out.println(startIndex);
   System.out.println(endIndex);

}


Where exactly do you get this exception?

Can you add the full file connectNode is in?

Your error usually arises when you try to declare a method inside another method.
Recheck your code and file structure.

You are right. I"m defining it in another method. I'll declare each class in different file. Thanks !

Upvote require 15 reputation and therefore I'm unable to upvote your post however I have accepted your answer.

Is it possible you're doing something like:
nodes.add(connectNode(start, end));

If that's the case then it means you're trying to insert something that is not suitable for this array list. More specifically you try to put void in a list of type Node.

I'm trying to print the start and end index of the ArrayList. I have already entered A,B,C,D,E,F characters in the arraylist using the nodes object. I'm wondering what's wrong with the method?

You still didn't write what is the flow you're running and where exactly this exception happens.
