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

12
  • 1
    Please include the code where you are having the import failure. Commented Jan 16, 2017 at 12:46
  • Are they in same project? Of if different ones, is the dependency configured well? Commented Jan 16, 2017 at 12:52
  • @PavanKumar in different projects and dependency has been configured. Commented Jan 16, 2017 at 12:56
  • @TimBiegeleisen code snippet added :) Commented Jan 16, 2017 at 12:56
  • What is the directory structure of A.java and B.java ? Does it follow the package names exactly? Commented Jan 16, 2017 at 12:57

4 Answers 4

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(); 
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

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

7 Comments

@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 :)
@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.
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.
@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.
@KevinWang i have attached the screenshot could you please have a look and let me know :)
|
0

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

Comments

0

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

Remove the import statement and re-import it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.