The type java.lang.Enum cannot be resolved - Getting error after importing Java project in Eclipse
Asked Answered
F

7

11

I am getting the following error after importing Java project (Non Maven) in Eclipse:

The type java.lang.Enum cannot be resolved. It is indirectly referenced from required .class files

I have couple of Java classes in my project and I am getting this compilation error in the first line of this below class (In the package declaration line)

package com.test.utils;

public enum Currency {
    PENNY, NICKLE, DIME, QUARTER
};

I checked my project's Java Build Path and in the Libraries tab all the jars and JRE System Library are present. Below is the .classpath content

<?xml version="1.0" encoding="UTF-8"?>
    <classpath>
        <classpathentry kind="src" path="src"/>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
        <classpathentry kind="lib" path="lib/***.jar"/> 
        <!-- list of jars -->
        <classpathentry kind="output" path="bin"/>
   </classpath>

I am using eclipse JUNO

Eclipse Java EE IDE for Web Developers.
Version: Juno Service Release 2
Build id: 20130225-0426 

and Java version is jdk 1.6.0_29 and the Compiler compliance level is 1.6 in eclipse.

I tried the following to resolve this issue

  1. Clean the project & build the project
  2. Delete and reimport the project and then again did the step 1
  3. Restart eclipse from the "File" menu and again did the step 1

But none of the above worked.

Please tell me how can I get rid of this compilation error.

Faulk answered 5/5, 2015 at 15:20 Comment(2)
see this : #3811512Tannatannage
Unlike forum sites, we don't use "Thanks", or "Any help appreciated", or signatures on Stack Overflow. See "Should 'Hi', 'thanks,' taglines, and salutations be removed from posts?. BTW, it's "Thanks in advance", not "Thanks in advanced".Murphy
F
7

I had the same issue and I just restarted my IDE and it worked

Fortress answered 20/12, 2020 at 23:21 Comment(1)
I just had the same problem, and in my case I had to clean the project using Project->Clean.Rosenquist
C
5

If you are using Eclipse, try running Project -> Clean

Caseycash answered 13/12, 2021 at 17:17 Comment(0)
C
2

This is happening more often for me after upgrading to the latest eclipse. Project clean does not resolve errors by itself, however after cleaning add/remove a space and resave the file does work.

Cherian answered 7/7, 2023 at 18:36 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Steep
U
1

Upgrading JDK package fixes the issue, after installing new JDK make sure you update your environment variables to new JDK installed path

Ubiquitous answered 31/1, 2023 at 19:23 Comment(0)
T
0

mvn package my project completed smoothly without errors. But eclipse IDE editor and problems panel persisted in telling me the type Enumset cannot be resolved.

I restarted eclipse but problems panel still says type Enumset cannot be resolved.

I went to Windows-Preferences-Java-Instalked JREs to change my default JRE from OpenJDK-17 to MSJDK-17 and the problem disappeared. Then I changed it back to OpenJDK-17.

The Eclipse 2023-12 I am using on Linux needed a knock on its head.

Tittle answered 14/3 at 17:24 Comment(0)
D
0

please check if enum class is having any compilation issues..

Duron answered 5/4 at 8:38 Comment(1)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewKrems
H
-1

Import this java.lang.Enum. It works for me.

Hepsibah answered 4/6, 2021 at 12:53 Comment(1)
Classes in package java.lang are always imported automatically and therefore do not need to be explicitly imported. Hence no need to add import java.lang.Enum.Krems

© 2022 - 2024 — McMap. All rights reserved.