I have an assignment to design a simple spam filter using a hash table to store a set of “bad words.” We discussed in class what a hash table is and how it’s used (ie. how elements are inserted, linear probing, quadratic probing, chained probing, etc.), but we never really discussed how to use the Java API Hashtable, which is required for this assignment. anyway, I’ve tried my best to implement it, however, I’m getting an exception that I cannot seem to trace with my debugger.
I’ve given up with inserting code here, I always have to spend time formatting it properly and it still doesn’t look good. So I’m putting it on Pastebin instead. It should make your lives easier too since it does syntax highlighting and line counting as well.
SpamFilter class
SpamFilterDriver class
I get NullPointerExceptions at the following lines in the SpamFilterDriver class:
line 78
line 96
line 115
Any help would be appreciated. I’m sure it’s probably something silly, but I’m just not seeing it at the moment.
Also, please note that the code is not finished yet in the least. The fact that the SpamFilter implements Serializeable will be used later on. Also, there are some empty methods, again, they will be implemented later, I just need to solve this problem first.
you have to initialize your
SpamFilter filter;in yourSpamFilterClass. before calling any of its methods.on line 78, you are calling a method
isBadWord().try initializing
filterlike below before calling any of its method. if you dont initialize your filter the default value is null and boom when you call a method with null BOOM BOOM NPE is thrown