0

I have seen the solution of this error message but it does not help, please help mere here.

string word = "hate";
string[] syn = S.GetSynonymsBySystem(word);

MessageBox.Show(syn[1].ToString());

When I run the above code, It does not show any error and give me the output in the messagebox as Emotion. Which means that there are no errors of linking to wordnet library.

So, When I took an array of words in and saved in final. And start searching one by one, Using the below code.

foreach (string keyword in final)
{
MessageBox.Show(keyword); //It shows the keyword here. which means no error in declaring my final array
string[] synonyms= S.GetSynonymsBySystem(keyword);
MessageBox.Show(synonyms.Length.ToString()); //Here is the error

} 

I get the following error:

An unhandled  exception of type "System.NullReferenceException" occured"

I dont know what is wrong? can any help me out? Thanks a lot.

  • Well perhaps one of the words *has no synonyms*, I cannot find any documentation on the method, but perhaps it only shows synonyms if there are synonyms and otherwise returns `null`. – Willem Van Onsem Apr 04 '17 at 15:53
  • `syn[1].ToString()` is not the same as `synonyms.Length.ToString()` – crashmstr Apr 04 '17 at 15:54
  • @crashmstr: No but if `syn[1].ToString()` succeeds, than `synonyms.Length.ToString()` should definitely succeed. – Willem Van Onsem Apr 04 '17 at 15:54
  • @WillemVanOnsem perhaps true, but complaining that one things works and a different thing does not work is like saying I like apples, so why don't I like this orange. – crashmstr Apr 04 '17 at 15:56
  • @crashmstr this is exactly what happening, I am stuck nowhere. There must be no chance of error in this phase but still they are there. – Muhammad Usman Apr 04 '17 at 16:01
  • 1. Set a breakpoint 2. examine the object state 3. Identity what is null 4. fix the problem. (it may not be what you think) – crashmstr Apr 04 '17 at 16:04
  • @WillemVanOnsem can you sort out what must be the problem? I am sure that the word has synonyms. As I checked it by using that particular single word – Muhammad Usman Apr 04 '17 at 16:04
  • @crashmstr how do we examine the object state? I am working in visual studio 2015 – Muhammad Usman Apr 04 '17 at 16:06
  • Do you understand how to debug? When you hit a breakpoint, add watches or just hover over things, and look at what it tells you. This is basic debugging 101. You *need* to be able to do this to solve your problem. We don't have all the code nor do we have the data set you are working on, so we cannot reproduce your issue. – crashmstr Apr 04 '17 at 16:08
  • @crashmstr I see it, actually it's easy in matlab. So, wasnt sure in studio. Thanks I will update you if this solves my problem – Muhammad Usman Apr 04 '17 at 16:10

0 Answers0