1

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 :)

Nurjan
  • 5,889
  • 5
  • 34
  • 54
Neethu Shaji
  • 120
  • 3
  • 4
  • 13

4 Answers4

2

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(); 
  }
}
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • Thanks you for the help :) that was a mistake from my end :( the screenshot i shared was just an example but for the actual code its still "Import cannot be resolved" in this case the solution is correct :) – Neethu Shaji Jan 16 '17 at 14:47
0

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>
Kevin Wang
  • 182
  • 1
  • 9
  • @kevin Wang thanks for your reply but this won't work we are not using MAVEN build. And i have already made the dependency clear :) – Neethu Shaji Jan 16 '17 at 13:06
  • @TimBiegeleisen, uh? would you elaborate why not? the problem he is facing is that class A is not in class path, so can be resolved. – Kevin Wang Jan 16 '17 at 13:08
  • I have the feeling that he is dealing with code that he wrote himself, and not external JARs, which therefore means code which won't be managed by Maven. – Tim Biegeleisen Jan 16 '17 at 13:10
  • @NeethuShaji, sorry I don't know about the IDE you're using, bottom line is you could go with the JAR way, which isn't ideal if you need to modify the classes in both projects. Maybe someone know the IDE also know a trick to get it work. Good luck. – Kevin Wang Jan 16 '17 at 13:12
  • @KevinWang i have attached the screenshot could you please have a look and let me know :) – Neethu Shaji Jan 16 '17 at 13:26
  • @NeethuShaji from the screenshot you posted it, yeah, it is ClassA, not just A. BTW, your IDE seems to me just good old Eclipse, is it called NWDS now? – Kevin Wang Jan 16 '17 at 14:10
  • @KevinWang Since i cannot post the screenshot of the actual code here. I tried wrote the same in Eclipse and pasted the screenshot. Also, yes that was a typo from my end about ClassA Sorry for that :( The actual code is written in NWDS IDE. – Neethu Shaji Jan 17 '17 at 02:11
0

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

Balkrushna Patil
  • 418
  • 6
  • 12
0

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

Remove the import statement and re-import it.

Tadele Ayelegn
  • 4,126
  • 1
  • 35
  • 30