Q:

ArrayList Error

I'm trying to make an ArrayList of my own type to store some values. However, I'm getting an error "x cannot be resolved or is not a field", where is source for example.
Here is a snippet of my code:
public class myClass {

public static void main(String args[]){
    addEdge("a","b", 10);
}

private static void addEdge(String source, String destination, int cost) {
      List<Edge> add = new ArrayList<Edge>();
      add.source = source; //error: source cannot be resolved or is not a field
      add.destination = destination; //error: destination cannot be resolved or is not a field
      add.cost = cost; //error: cost cannot be resolved or is not a field
}
}

class Edge{
    String source;
    String destination;
    int cost;
}

As you can see I get errors in my addEdge method. I'm

A:

In your code
List<Edge> add = ... 
add.source = ...

you are trying to access source field via add reference which is of type List but List doesn't have source field (which is what error message is trying to say). You need to access this fields from Edge, not from List.
So try something more like
Edge edgeInstance = new Edge();
edgeInstance.source = source;
edgeInstance.destination = destination; 
edgeInstance.cost = cost;
...

listOfEdges.add(edgeInstance);

Anyway you should avoid making your fields accessible from outside of your class. They should be private and you should initialize them via constructor or via setters.
Also it seems that each time you are calling your method you are creating new List
List<Edge> add = new ArrayList<Edge>();

and you are not reusing it anywhere outside of this method which seems kind of pointless. 

