I am trying to write program and keep getting a nullPointerException when I call a particular method, what does this mean ?
-
This question and the code looks extremely familiar. I've seen this definitely before a few hours ago, but can't find it now... It was answered there.Boris– Boris2011-03-05 16:09:41 +00:00Commented Mar 5, 2011 at 16:09
-
@stackoflow, Hm.. Have you recreate topic and delete previous? (-1 until answer)Stan Kurilin– Stan Kurilin2011-03-05 16:12:51 +00:00Commented Mar 5, 2011 at 16:12
-
2This question is extremely similar to stackoverflow.com/questions/5185577/java-generic-arguments/…Zach L– Zach L2011-03-05 16:19:51 +00:00Commented Mar 5, 2011 at 16:19
-
This is not homework, and yes this is a previously submitted topic - I phrased my last question badly, it got spammed, I spoke to a mod who deleted it so that it wouldn't confuse any people trying to learn from it. Acceptable answer ?Frank Burns– Frank Burns2011-03-05 16:58:55 +00:00Commented Mar 5, 2011 at 16:58
-
-1 undoned as answer provided.Stan Kurilin– Stan Kurilin2011-03-05 17:51:20 +00:00Commented Mar 5, 2011 at 17:51
Add a comment
|
1 Answer
I think it should be
private int size; //non static
private static <S extends Comparable<S>> MyList<S> leftHalf(MyList<S> list) {
MyList<S> leftSide = new MyList<S>();
int middle = list.size() /2;
for (int countToMiddle = 0; countToMiddle < middle; countToMiddle++) {
leftSide.addEnd(list.head());
}
return leftSide;
}
if no, please provide more information about what this method should do.
upd: construction issue
public MyList() { //takes no arguments
nodes = null;
}
public MyList(T... args) { //takes any number of arguments
this();
for(T t : args){
add(t);
}
}
upd: addEnd issue
public void addEnd(T item) {
if (nodes == null) {
nodes = new NodesList<T>(item, null);
return;
}
if (nodes.tail == null) {
nodes.tail = new NodesList<T>(item, null);
} else {
nodes.tail == new NodesList<T>(nodes.tail, item);
}
}
17 Comments
Frank Burns
This method should split the list into two lists, in the first(leftSize) it will contain the elements from 0 to n/2, in the second, rightSide, it will contain the elements from n/2 to n. Unfortunately my implementation does not seem to work, as, when I call 'MyList list = new MyList<Long>( 1L, 2L, 3L ); //3 entries list.print();', I get the error cannot find symbol symbol : constructor MyList(long,long,long)
Stan Kurilin
@stackoflow, I think, this method should do exactly what you want) , correct? Optionally you can remove static modifier and list argument.
Stan Kurilin
@stackoflow, about constructor : you should create constructor with vararg to do things like this. It's other question)
Frank Burns
I believe it should, by my logic, which is often incorrect! I cannot test it, however. Unfortunately I am still having the error that when I call the MyList constructor, I get the message "cannot find symbol symbol : constructor MyList(long,long,long)".
Frank Burns
@Stas , could you please elaborate on using vararg ? Thanks.
|