1

I have created a List call nodes_ and initialized as a ArrayList, when I add something to nodes_ , all is null. There is a piece of code :

public class MyOocmdgGeneration1 {
private List<Node> nodes_ = new ArrayList<Node>();

public MyOocmdgGeneration1() {
    findDependency();
}

private void findDependency() {

    ClassNode c1 = new ClassNode();
    FieldNode x = new FieldNode();
    MethodNode c1Constructor = new MethodNode();
    MethodNode m1 = new MethodNode();

    nodes_.add(c1);
    nodes_.add(x);
    nodes_.add(c1Constructor);
    nodes_.add(m1);

and there is another piece of other class:

public abstract class Node {
private String path;
private List<Node> callees;
private List<Node> callers;
private List<Node> children;
private Node parent;
private int id;

public Node() {
    this.callees = new ArrayList<>();
    this.callers = new ArrayList<>();
    this.children = new ArrayList<>();
}

public Node(String path, List<Node> callees, List<Node> callers) {
    this();
    this.path = path;
    this.callees = callees;
    this.callers = callers;
    this.children = new ArrayList<>();
}

public Node(int id, String path, Node parent) {
    this();
    this.id = id;
    this.path = path;
    this.parent = parent;
    parent.addChild(this);
}

When i debuged , it looks like this :debug image

2 Answers 2

2

What you're seeing ("null") is the output of toString() called on each of those classes. They aren't actually null.

How can you tell? The debugger shows each entry like ClassNode@464. That refers to a specific instance, not null.

Sign up to request clarification or add additional context in comments.

1 Comment

Ohhhh, yeahhhhh , thank you, I found my problem . It is not a null arraylist
0

The nodes are not null. The objects are all there, but their toString representation is "null".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.