Results 1 to 7 of 7
Thread: I am confused
- 10-30-2009, 10:41 PM #1
Member
- Join Date
- Oct 2009
- Posts
- 36
- Rep Power
- 0
I am confused
Hi
When I wrote this code:
public class Main {
public class node {
int[] nod = {0, 0, 0};
}
public static node[] state = new node[4];
public static void divide(int[] M )
{
state[0].nod[0] = M[0];
state[0].nod[1] = M[1];
state[0].nod[2] = M[2];
state[1].nod[0] = M[3];
state[1].nod[1] = M[4];
state[1].nod[2] = M[5];
state[2].nod[0] = M[6];
state[2].nod[1] = M[7];
state[2].nod[2] = M[8];
state[3].nod[0] = M[9];
state[3].nod[1] = M[10];
state[3].nod[2] = M[11];
}
public static void main(String[] args) {
int[] M = {0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0};
divide(M);
}
}
there is no error but when I try run it this message appear::eek::eek:
Exception in thread "main" java.lang.NullPointerException
at cry.Main.divide(Main.java:21)
at cry.Main.main(Main.java:37)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
what it means ???:confused::confused:
- 10-30-2009, 10:44 PM #2Java Code:
public static node[] state = new node[4];
Java Code:node[0] = new Node(); node[1] = new Node(); node[2] = new Node(); node[3] = new Node();
Last edited by mrmatt1111; 10-30-2009 at 10:47 PM.
My Hobby Project: LegacyClone
- 10-30-2009, 11:28 PM #3
Member
- Join Date
- Oct 2009
- Posts
- 36
- Rep Power
- 0
I can't understand u..could you please explain more..
first I create object node which contain array of integer nod this array length is 3
then I create array from that object node its name state and this array length is 4
so where should I put the constructor ..
thanks
-
.... um, he showed you where to put the calls to the Node constructor.
- 10-30-2009, 11:56 PM #5
Member
- Join Date
- Oct 2009
- Posts
- 36
- Rep Power
- 0
sorry sir but I am new in Java so can you tell me exactly where I should but that call
and I don't have Node type it's node
did you mean
state[0]=new node();
-
It should be Node as class names should begin with a capital letter. I recommend you change it.
After you declare your array of four Nodes, but before you use them, use a for loop to loop through the array and initialize each Node in the array by calling the Node constructor.
Java Code:for (int i = 0; i < state.length; i++) { state[i] = new Node(); // again, the Node class should be capitalized. }
Much luck.Last edited by Fubarable; 10-31-2009 at 12:06 AM.
- 10-31-2009, 12:32 AM #7
Member
- Join Date
- Oct 2009
- Posts
- 36
- Rep Power
- 0
Similar Threads
-
Very confused Plz help!!
By ratb0y in forum NetBeansReplies: 0Last Post: 02-14-2009, 05:34 PM -
Confused
By coldfire in forum New To JavaReplies: 3Last Post: 01-13-2009, 02:00 PM -
confused
By updev in forum AWT / SwingReplies: 6Last Post: 11-14-2008, 04:33 PM -
a lot confused
By vineethraj in forum New To JavaReplies: 4Last Post: 01-18-2008, 01:36 AM -
what does it mean:confused:
By sivasayanth in forum New To JavaReplies: 2Last Post: 01-12-2008, 05:52 AM
Bookmarks