[java] Eclipse error ... cannot be resolved to a type

I have a dynamic web project that I am working on to migrate a jsp/servlet app from JRun to Tomcat.

I am getting the error: com.ibm.ivj.eab.dab.DatastoreJDBC cannot be resolved to a type.

I have the *.class files sitting inside a com/ibm/ivj/eab/dab folder (exactly how I found them). I have tried creating a jar file and adding that to the build path via "Add External Jar", I have also tried adding an "External Class Folder" and pointing to the folder that contains the "com" directory in question.

Still, the error persists. What is strange is if I start typing the package name eclipse actually auto-completes the class for me! (pictured below). Any ideas would be greatly appreciated. Maybe the classes were compiled for a much older java version and that is causing trouble? Maybe there is something I need to do to ensure the classes end up in the WEB-INF/lib directory?

Ienter image description here

This question is related to java eclipse

The answer is


Also If you are using mavenised project then try to update your project by clicking Alt+F5. Or right click on the application and go to maven /update project.

It builds all your components and resolves if any import error is there.


Solved the problem by dropping the jar into WEB_INF/lib.


  • Right click Project > Properties
  • Java Build Path > Add Class Folder
  • Select the bin folder
  • Click ok
  • Switch Order and Export tab
  • Select the newly added bin path move UP
  • Click Apply button

enter image description here


Project -> Build Path -> Configure Build Path
Select Java Build path on the left menu, and select "Source"
 click on Excluded and then Include(All) and then click OK
    Cause : The issue might because u might have deleted the CLASS files 
 or dependencies on the project

For maven users:

Right click on the project

Maven

Update Project


There are two ways to solve the issue "cannot be resolved to a type ":

  1. For non maven project, add jars manually in a folder and add it in java build path. This would solve the compilation errors.
  2. For maven project, right click on the project and go to maven -> update project. Select all the projects where you are getting compilation errors and also check "Force update of snapshots/releases". This will update the project and fix the compilation errors.

I just closed all the files and reopened them, and voila!!! Hope this helps someone in the future ;)


copying the jar files will resolve. If by any chance you are copying the code from any tutorials, make sure the class names are spelled in correct case...for example i copied a code from one of the tutorials which had solr in S cap. Eclipse was continiously throwing the error and i also did a bit of googling ...everything was ok and it took 30 mins for me to realise the cap small issue. Am sure this will help someone


For maven users:

  • Right click on the project
  • Maven
  • Update Project

Solution : 1.Project -> Build Path -> Configure Build Path

2.Select Java Build path on the left menu, and select "Source"

3.Under Project select Include(All) and click OK

Cause : The issue might because u might have deleted the CLASS files or dependencies on the project


Download servlet-api.jar file and paste it in WEB-INF folder it will work


Also, there is the solution for IvyDE users. Right click on project -> Ivy -> resolve It's necessary to set ivy.mirror property in build.properties


First you need to update the pom.xml by adding below

    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>4.1.6.RELEASE</version>
    </dependency>

1] Right click your project name.

2] Click Properties.

3] Click Java Build Path.

4] Check on 'Maven Dependencies' in Order and Export tabl.

In my case, previously it was not enabled. So when I enabled it my @GetMapping annotation works fine..


For many new users don't forget to add an asterisk (*) after your import statements if you wanna use all the classes in a package....for example

import java.io.*;

public class Learning 
{
    public static void main(String[] args) 
    {
        BufferedInputStream sd = new BufferedInputStream(System.in);
            // no error
    }
}

================================================================

import java.io;

public class Learning 
{
    public static void main(String[] args) 
    {
        BufferedInputStream sd = new BufferedInputStream(System.in);
            // BufferedInputStream cannot be resolved to a type error
    }
}

Easy Solution:
Go to

Project property -> java builder path -> maven -> find c3p0-0.9.5.2.jar

and see the location where the file is stored in the local repository and go to this location and delete the repository manually.

G


To solve the error "...cannot be resolved to a type.." do the followings:

  1. Right click on the class and select "Build Path-->Exclude"
  2. Again right click on the class and select "Build Path-->Include"

It works for me.


I was importing the source into the wrong folder. I'm so used to using Visual Studio, that I expect all IDE's to be so accommodating.


Project -> Clean

can at least sometimes be sufficient to resolve the matter.