Jump to content

Recommended Posts

Posted

I am trying to make a search function that finds a change in a text and then finds a string that matched the hint from a word bank and narrows down your searches.

 

Here is the one method that is causing the error and the line that it is putting I will make but I think it is just the general area.

 

	public String[] wordSearchHint(String[] choices, int chars, String hint) {
		if (choices.length > 0) {
			String lasthint = "";
			for (int i = 0; i < chars; i++) {
				lasthint = lasthint + "_";
			}
			hint.replaceAll(" ", "_");
			int loc = 0;
			char letter = ' ';
			boolean change = false;
			boolean found = false;
			String[] newchoices = new String[100];
			for (int i = 0; i < hint.length(); i++) {
				if (!(hint.charAt(i) == lasthint.charAt(i))) {
					loc = i;
					letter = hint.charAt(i);
					change = true;
					break;
				}
			}
			if (change && choices.length > 0) {
				for (int i = 0; i < choices.length; i++) {
					if (!choices[i].isEmpty()) {    		//<<<<<<<<<<<<<<<<<<<<<<< <this is the exact line
						if (choices[i].charAt(loc) == letter) {
							newchoices[i] = choices[i];
							found = true;
						}
					}
				}
			} else {
				if (hint == lasthint) {
					return choices;
				}
			}
			if (found) {
				return newchoices;
			} else {
				return choices;
			}
		} else {
			return choices;
		}
	}

 

Posted

It seems pretty clear. Your choices array has a null value at that index. But you haven't shown the code you use to create the choices array so we can't help you. But to debug you can just print out the values of the array to the console and you'll quickly see what the problem is.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.