I want to be able to read strings from a file, and search if a word im looking for is in there. if it is, a message pane will pop up saying yes. if not, then it will say no. Right now, i can't seem to get the two methods to connect. THeres always an error.

StringTokenizer st = new StringTokenizer(phrase);// Created a new object, that will allow me to tokenize String.

/** Basically, boolean starts out as false. if the StringTokenizer st has more token, it will keep
* reading each word. If one of the words in the string equal to the word the user entered, then
* boolean will turn true.
*/

Error:
NullPointerException:
at java.util.StringTokenizer.<init>(Unknown Source)
at java.util.StringTokenizer.<init>(Unknown Source)
at AccessFile.search(AccessFile.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
at java.lang.reflect.Method.invoke(Unknown Source)
>

PLz help. i really need it. Some tips, editing of the code, etc.

08-02-2007, 04:55 AM

cruxblack

This seems like the extension of the String Tokenizer problem u write in another thread
I'll try analyzin ur code for now, ill inform u if i get some progress, good luck with ur project

08-03-2007, 04:47 AM

cruxblack

I don't know if u recognize, but u didn't put any link between the 2 method actually, what were u trying to do :confused:

From my point of view it seems that u were using te search method to search inside the file and find a matching words
The problem is in the search method, u declare the string tokenizer with the input parameter of phrase, in which phrase itself havent been initialized at all, check ur code, it's bit hard reading the code without the indents and tabs

This error

Code:

at java.util.StringTokenizer.<init>(Unknown Source)
at java.util.StringTokenizer.<init>(Unknown Source)
at AccessFile.search(AccessFile.java:30)

refer to the instantiation of the StringTokenizer after all, it could not find variable phrase, which leads to null