[Java Help] will provide porn if solved

Code:
String crazy = new String(successor(current.entry.word));
			System.out.println(crazy);
still gives the eception
 
Exception in thread "main" java.lang.NullPointerException
at OrderedDictionary.successor(OrderedDictionary.java:154)
at OrderedDictionary.remove(OrderedDictionary.java:129)
at Query.main(Query.java:42)

Post for us a chunk of code around line 154 of ordereddictionary.java, line 129 of ordereddictionary.java, and line 42 of query.java. Mark the actua line in bold or something.
 
I'm not getting the

"Exception in thread "main" java.lang.NullPointerException
at OrderedDictionary.successor(OrderedDictionary.java :154)
at OrderedDictionary.remove(OrderedDictionary.java:12 9)
at Query.main(Query.java:42)"

when I compile/run it. Please tell me I'm missing something, because it seems to work for me.

Java.PNG
 
from OrderedDictionary line 127ish
Code:
			// get successor of node to delete (current)
			[b][size=3]String crazy = new String(successor(current.entry.word));[/b][/size]
			System.out.println(crazy); 
			find(word);
			// connect parent of current to successor instead
			if(current == root) {
				root = successor;
			}
from line 149ish
Code:
if (current.right != null) {
			System.out.println("minimum(current.right.entry.word): " + minimum(current.right.entry.word));
			[b][size=3]return minimum(current.right.entry.word);[/b][/size]
		}
from query (not really necessary but anyway)
Code:
				if (command.compareTo("delete") == 0) {
					dictionary.remove(word);
				}
 
worstaim, you compile then run from cmd line "java Query large.txt"

then once you get the command promt put in "delete doodlesack"
 
Ok, so briefly looking at the code you provided, I suppose there could be a problem with the line you marked in bold

success.entry.word = successor(current.entry.word);

Aren't you passing by reference here? So once successor goes out of scope and is destroyed, success.entry.word becomes the null pointer?

It's been a long while since I've done much programming, but my guess would be that successor(current.entry.word) goes out of scope, gets picked up by the garbage collector, and turns into nothingness. Create the new string there and see what happens.
 
successor() should be returning a string
i just want to give that string to the word field of success, there's no passing reference here is there? :/

and

String crazy = new String(successor(current.entry.word));

gives the saem exception
 
Last edited:
not a class
it's a method
public String minimum(String word) so it gets a word and returns a word
public String successor(String word) so it gets a word and returns a word
String crazy = new String(successor(current.entry.word));

so wtf :(
 
not a class
it's a method
public String minimum(String word) so it gets a word and returns a word
public String successor(String word) so it gets a word and returns a word
String crazy = new String(successor(current.entry.word));

so wtf :(

So minimum is a method that returns a string? Try the whole new string thing there in the return statement. I have no idea if it'll work, but that's where the null pointer appears to be coming from.
 
didn't work :/ i returned new strings from both methods to a new string and it still gives it
it's as if successor isn't returning a string, but i dont know why
 
Back
Top