Re: link Arraylist in java
Why can you not post your code surrounded by code tags, this is the third time I have had to ask you. The bottom of everyone of my posts shows how to do it - see the blue text.
In future I will not answer posts from you unless the code is wrapped in code tags.
The Node classes 'child' field must NOT be declared as static. Static means there will be just one child ArrayList shared by every object of type Node which means every Node object will be at the same level. This is wrong, every Node object must have it's own list of its children - so remove the static modifier.
The problem is with how you are trying to access the Node's child list. You are using the Node class ie Node.child when you should be using a Node object ie myNode.child.
Your code appears to be full of problems but unless it is formatted properly I'm not going to try to wade thought it to figure out what you are doing wrong.
Quote:
here i used clearly define childern as integer so i didnot use generic type arraylist
You haven't defined 'childern' at all. You have declared a variable 'child', which is badly named as it doesn't reference a child at all but rather it references a collection of children hence I called it children.
You have declared your data type as int which means you don't need to make the Node class generic but the ArrayList is a generified class so you have to specify what type you are putting in it or you will get the compiler warnings. ie:
Code:
protected ArrayList<Node> child;
...
child = new ArrayList<Node>();
Re: link Arraylist in java
thanks a lot. your link go to http://www.keang.co.uk/. here i can't
find the code. can you post the entire code. because i have to understand the code.
Re: link Arraylist in java
This web site contains fully featured classes and code examples that may be useful to other, all the code can be found by selecting the appropriate menu on the left hand side.
What code were you looking for?
Quote:
can you post the entire code.
No.
Quote:
because i have to understand the code.
You learn by writing code yourself and not by getting others to write it for you.
Re: link Arraylist in java
thanks a lot i have almost finished my work using your suggestion