-3

Unable to invoke the class, although i defined it. I tried with many methods.

Error:

error: cannot find symbol 
StopWord d= new StopWord();//test for StopWord 
^ 
symbol: class StopWord

Code:

This is my main file

public  static void main(String[]args)throws Exception {
    StopWord dis= new StopWord();
    System.out.println("whencesoever is in Hahtable :" +
            dis.isStopWord("whencesoever"));
}

And my file that contains Class StopWord is

public class StopWord {
   public static boolean isStopWord(String s) {
    //statements
   }
}

Regards!!!

Bentaye
  • 9,403
  • 5
  • 32
  • 45
Anu Prabha
  • 17
  • 1
  • you need a return statement in isStopWord to compile: `return true;` will do. – Bentaye Mar 19 '18 at 08:34
  • This is my exact error error: cannot find symbol StopWord d= new StopWord();//test for StopWord ^ symbol: class StopWord.... Sorry Im new to java may i know what is sb?? – Anu Prabha Mar 19 '18 at 08:34
  • 2
    I don't see any reason to downvote the question, the code might be low quality as OP is an unexperienced programmer, but the question itself is clearly related to programming and the user needs some leads to resolve the issue. – Tatranskymedved Mar 19 '18 at 08:52
  • Possible duplicate of [What does a "Cannot find symbol" compilation error mean?](https://stackoverflow.com/questions/25706216/what-does-a-cannot-find-symbol-compilation-error-mean) – Piro Mar 19 '18 at 10:00

2 Answers2

1

Did you import the StopWord class ?

Side note:

if isStopWord is static, you should call it like this:

    StopWord.isStopWord("whencesoever"));

if you want to call dis.isStopWord("whencesoever")) do not mark it static, ie

public boolean isStopWord(String s)
Bentaye
  • 9,403
  • 5
  • 32
  • 45
  • 1
    Ofcourse I have return statement... bt i haven't mentioned here!!! Still getting the same error... And should i import stopword in my main file??? – Anu Prabha Mar 19 '18 at 09:26
  • you should import `StopWord` in the file where you have the main method. – Bentaye Mar 19 '18 at 09:58
  • But i use same package for both the file... Is there need to import my class into main file – Anu Prabha Mar 19 '18 at 10:11
  • do you have an error at compile time or at run time? also can you give the exact line which give the error? – Bentaye Mar 19 '18 at 11:32
  • My error falls at compile time... I use `package tf_idf;` in both the file.. When i compile my main file it throws an `error: cannot find symbol` – Anu Prabha Mar 20 '18 at 04:14
-1

This may help

 public Class Test{
        public  static void main(String[] args) throws Exception
        {
            java.lang.StringIndexOutOfBoundsException sb;

            StopWord dis= new StopWord();
            System.out.println("whencesoever is in Hahtable :" +
                    dis.isStopWord("whencesoever"));
        }
    }

There is no return statement.

public class StopWord{
   public static boolean isStopWord(String s){
           return true;
      }
  }

static is not required.

 public class StopWord{
       public boolean isStopWord(String s){
               return true;
          }
      }
Nabin Kumar Khatiwada
  • 1,546
  • 18
  • 19