Neethu Shaji
Neethu Shaji

Reputation: 120

Import cannot be resolved in java

enter image description hereI am getting:

import com.test.foo.A cannot be resolved 

IDE I am using is NWDS.

I have a class A which is declared as public, I have a class B which is declared as public final. Both are declared in different packages.

Class A in com.test.foo

Class B in com.test.foo1

I am trying to import a public method from class A to class B but I am getting the above mentioned error in IDE.

Both are in different projects.

Code snippet as below :-

package com.test.foo 

public class A {

    public static void method1(){
    ....some code ....
    }

}

-----

package com.test.foo1

import com.test.foo.A // i'm getting error here as import cannot be resolved

public final class B {

    private method2(){

    ...... some code....
     A.method1(); // import cannot be resolved error
    }
}

Can any help help on this?

Thanks in advance for you help :)

Upvotes: 1

Views: 10945

Answers (4)

Tadele Ayelegn
Tadele Ayelegn

Reputation: 4706

Even if you imported the right class and still getting this error, use this trick.

Remove the import statement and re-import it.

Upvotes: 0

Balkrushna Patil
Balkrushna Patil

Reputation: 466

To solve given issue Please follow below link stackoverflow.com/a/48381463/5093657

Upvotes: 0

Gabriele Mariotti
Gabriele Mariotti

Reputation: 363439

In your image you have the class ClassA not A.

So the error is:

 "import com.test.foo.A cannot be resolved"

You should import the class ClassA.

package com.test.foo1

import com.test.foo.ClassA;

public final class B {

  private method2(){

    //...... some code....
    ClassA.method1(); 
  }
}

Upvotes: 2

Kevin Wang
Kevin Wang

Reputation: 182

This is like trying to copy text by clicking "copy" button on a computer, and clicking "paste" button on another computer. Quite amusing. :-)

  • Well, a general Java way is you build the project that contains A as a JAR, and use it as a library in another project that contains B.

  • Or if you organize your project using Maven, you can import another project as dependency. Something like:

?

<project>
   ...
   <dependencies>
      <dependency>
         <groupId>yourgroup</groupId>
         <artifactId>myejbproject</artifactId>
         <version>2.0</version>
         <scope>system</scope>
         <systemPath>path/to/myejbproject.jar</systemPath>
      </dependency>
   </dependencies>
   ...
</project>

Upvotes: 0

Related Questions