Java error cannot access class

When I try to make a project in IntelliJ I receive the following error on this line: Sentence sent = new Sentence(); sent.emptySegments(); Error: Error:(151, 10) java: cannot access javax.xml.b...

When I try to make a project in IntelliJ I receive the following error on this line:

Sentence sent = new Sentence();
 sent.emptySegments();

Error:

Error:(151, 10) java: cannot access javax.xml.bind.RootElement
class file for javax.xml.bind.RootElement not found

Sentence is a class which implements the RootElement interface

import javax.xml.bind.RootElement;
...
public class Sentence extends MarshallableRootElement implements RootElement   {

All packages exist and I can jump to declaration of each interface or class but I don’t know why IntellJ says it cannot access or find them? However RootElement is an interface and not a class

public interface RootElement extends Element {
    void validate() throws StructureValidationException;
}

The above declaration is in a jar file named jaxb-rt-1.0-ea.jar and it exists in the Project librarians.

asked Jul 24, 2016 at 7:18

Ahmad's user avatar

AhmadAhmad

8,2799 gold badges71 silver badges123 bronze badges

4

Try this

  1. Go to File
  2. Invalidate Caches/Restart
  3. You can choose only Invalidate and restart

(See Invalidate caches on IntelliJ’s manual)

bruno's user avatar

bruno

2,1891 gold badge18 silver badges30 bronze badges

answered Aug 1, 2019 at 16:02

Meena Chaudhary's user avatar

Meena ChaudharyMeena Chaudhary

9,41816 gold badges57 silver badges92 bronze badges

3

The project contained several modules. While the library was added to the project libraries, some modules lacked it in their dependency part. So I solved the problem using the following steps in IntelliJ

Creating a module library and adding it to the module dependencies:

  1. Open the Project Structure dialog (e.g. Ctrl+Shift+Alt+S).
  2. In the left-hand pane of the dialog, select Modules.
  3. In the pane to the right, select the module of interest.
  4. In the right-hand part of the dialog, on the Module page, select the Dependencies tab.
  5. On the Dependencies tab, click + (on the top right) and select Jars or directories.
  6. In the dialog that opens, select the necessary files and folders. These may
    be individual .class and .java files, directories and archives
    (.jar and .zip) containing such files as well as directories with
    Java native libraries (.dll, .so or .jnilib).
  7. Click OK. If necessary, select the Export option and change the dependency scope.
  8. Click OK in the Project Structure dialog.

answered Jul 24, 2016 at 8:11

Ahmad's user avatar

AhmadAhmad

8,2799 gold badges71 silver badges123 bronze badges

3

File -> Invalidate Caches/ Restart
this worked for my after long hours of effectiveless

answered Dec 16, 2019 at 13:16

Patrycja Cz's user avatar

Patrycja CzPatrycja Cz

2112 silver badges2 bronze badges

Rebuilding project worked for me.

answered Apr 24, 2019 at 11:41

Arda Ç.'s user avatar

Arda Ç.Arda Ç.

5055 silver badges7 bronze badges

0

Deleting the .idea folder and then running Invalidate Caches/Restart worked for me.

answered Oct 26, 2020 at 2:43

Yumi H's user avatar

Yumi HYumi H

1211 silver badge10 bronze badges

1

It also may be because you don’t have dependencies in classpath, which used in dependencies.
For example: you use library A, but class you’re using from A has superclass from library B. But you didn’t add B to classpath.

סטנלי גרונן's user avatar

סטנלי גרונן

2,87923 gold badges48 silver badges66 bronze badges

answered Mar 27, 2020 at 7:39

Alexander S's user avatar

If it is a single file, you can try deleting the file and undoing it. It seems to reindex that particular file alone, which is much faster than Invalidate Caches/Restart. As a precautionary measure, you can take a backup of the file before deleting, just in case if something goes awry.

Another reason might be different versions of same library with more/less methods. This happened for me with Gradle. Sometimes it compiles fine and sometimes, it doesn’t. Just find and remove the unnecessary ones.

answered Nov 25, 2021 at 12:49

Mohamed Safeuq J's user avatar

My Gradle/IntelliJ «big hammer»

(Optional, but preferred). Close all instances of IntelliJ or any other Java IDE.

delete the «.idea» folder (<< intellij specific, or whatever «workspace» folder your IDE uses)

…………..

./gradlew --stop       
      OR
gradle --stop

(now delete the folders)

rm -rf $HOME/.gradle/caches/

rm -rf $HOME/.gradle/build-cache-tmp/

(now resume normal gradlew commands like:)

./gradlew clean build

answered Dec 3, 2020 at 15:36

granadaCoder's user avatar

granadaCodergranadaCoder

25.2k9 gold badges104 silver badges140 bronze badges

For me just worked, turn off windows defender / add exclusion project folder / idea process.

answered Jan 26, 2021 at 5:38

Aleksei Vekovshinin's user avatar

Similar problem can happen if a library is imported with maven scope runtime.

In such case it isn’t accessible by your classes located under src/main/java.

Only classes in src/test/java can directly use runtime dependencies.

answered Mar 18, 2021 at 10:01

radzimir's user avatar

radzimirradzimir

1,01812 silver badges8 bronze badges

I removed this location «amazonaws» file and clean install later run

/Users/testuser/.m2/repository/com/amazonaws

answered Nov 22, 2021 at 15:00

Mevlüt Beder's user avatar

If you’ve made it this far because rebuilding or invalidating the cache didn’t work work you, I found that deleting the class and adding a new one with the same code worked.

answered Sep 19, 2022 at 16:06

David Pement's user avatar

In my case there was an old .iml file in the module causing these problems. So if nothing else worked for you, try looking for one.

answered Nov 22, 2022 at 10:08

Lenymm's user avatar

LenymmLenymm

8671 gold badge6 silver badges25 bronze badges

⬇ Download the last version of IntelliJ.

▶ Install it.

Worked for me. ✌

answered Jan 2 at 12:17

vvauban's user avatar

vvaubanvvauban

1095 silver badges8 bronze badges

When I try to make a project in IntelliJ I receive the following error on this line:

Sentence sent = new Sentence();
 sent.emptySegments();

Error:

Error:(151, 10) java: cannot access javax.xml.bind.RootElement
class file for javax.xml.bind.RootElement not found

Sentence is a class which implements the RootElement interface

import javax.xml.bind.RootElement;
...
public class Sentence extends MarshallableRootElement implements RootElement   {

All packages exist and I can jump to declaration of each interface or class but I don’t know why IntellJ says it cannot access or find them? However RootElement is an interface and not a class

public interface RootElement extends Element {
    void validate() throws StructureValidationException;
}

The above declaration is in a jar file named jaxb-rt-1.0-ea.jar and it exists in the Project librarians.

asked Jul 24, 2016 at 7:18

Ahmad's user avatar

AhmadAhmad

8,2799 gold badges71 silver badges123 bronze badges

4

Try this

  1. Go to File
  2. Invalidate Caches/Restart
  3. You can choose only Invalidate and restart

(See Invalidate caches on IntelliJ’s manual)

bruno's user avatar

bruno

2,1891 gold badge18 silver badges30 bronze badges

answered Aug 1, 2019 at 16:02

Meena Chaudhary's user avatar

Meena ChaudharyMeena Chaudhary

9,41816 gold badges57 silver badges92 bronze badges

3

The project contained several modules. While the library was added to the project libraries, some modules lacked it in their dependency part. So I solved the problem using the following steps in IntelliJ

Creating a module library and adding it to the module dependencies:

  1. Open the Project Structure dialog (e.g. Ctrl+Shift+Alt+S).
  2. In the left-hand pane of the dialog, select Modules.
  3. In the pane to the right, select the module of interest.
  4. In the right-hand part of the dialog, on the Module page, select the Dependencies tab.
  5. On the Dependencies tab, click + (on the top right) and select Jars or directories.
  6. In the dialog that opens, select the necessary files and folders. These may
    be individual .class and .java files, directories and archives
    (.jar and .zip) containing such files as well as directories with
    Java native libraries (.dll, .so or .jnilib).
  7. Click OK. If necessary, select the Export option and change the dependency scope.
  8. Click OK in the Project Structure dialog.

answered Jul 24, 2016 at 8:11

Ahmad's user avatar

AhmadAhmad

8,2799 gold badges71 silver badges123 bronze badges

3

File -> Invalidate Caches/ Restart
this worked for my after long hours of effectiveless

answered Dec 16, 2019 at 13:16

Patrycja Cz's user avatar

Patrycja CzPatrycja Cz

2112 silver badges2 bronze badges

Rebuilding project worked for me.

answered Apr 24, 2019 at 11:41

Arda Ç.'s user avatar

Arda Ç.Arda Ç.

5055 silver badges7 bronze badges

0

Deleting the .idea folder and then running Invalidate Caches/Restart worked for me.

answered Oct 26, 2020 at 2:43

Yumi H's user avatar

Yumi HYumi H

1211 silver badge10 bronze badges

1

It also may be because you don’t have dependencies in classpath, which used in dependencies.
For example: you use library A, but class you’re using from A has superclass from library B. But you didn’t add B to classpath.

סטנלי גרונן's user avatar

סטנלי גרונן

2,87923 gold badges48 silver badges66 bronze badges

answered Mar 27, 2020 at 7:39

Alexander S's user avatar

If it is a single file, you can try deleting the file and undoing it. It seems to reindex that particular file alone, which is much faster than Invalidate Caches/Restart. As a precautionary measure, you can take a backup of the file before deleting, just in case if something goes awry.

Another reason might be different versions of same library with more/less methods. This happened for me with Gradle. Sometimes it compiles fine and sometimes, it doesn’t. Just find and remove the unnecessary ones.

answered Nov 25, 2021 at 12:49

Mohamed Safeuq J's user avatar

My Gradle/IntelliJ «big hammer»

(Optional, but preferred). Close all instances of IntelliJ or any other Java IDE.

delete the «.idea» folder (<< intellij specific, or whatever «workspace» folder your IDE uses)

…………..

./gradlew --stop       
      OR
gradle --stop

(now delete the folders)

rm -rf $HOME/.gradle/caches/

rm -rf $HOME/.gradle/build-cache-tmp/

(now resume normal gradlew commands like:)

./gradlew clean build

answered Dec 3, 2020 at 15:36

granadaCoder's user avatar

granadaCodergranadaCoder

25.2k9 gold badges104 silver badges140 bronze badges

For me just worked, turn off windows defender / add exclusion project folder / idea process.

answered Jan 26, 2021 at 5:38

Aleksei Vekovshinin's user avatar

Similar problem can happen if a library is imported with maven scope runtime.

In such case it isn’t accessible by your classes located under src/main/java.

Only classes in src/test/java can directly use runtime dependencies.

answered Mar 18, 2021 at 10:01

radzimir's user avatar

radzimirradzimir

1,01812 silver badges8 bronze badges

I removed this location «amazonaws» file and clean install later run

/Users/testuser/.m2/repository/com/amazonaws

answered Nov 22, 2021 at 15:00

Mevlüt Beder's user avatar

If you’ve made it this far because rebuilding or invalidating the cache didn’t work work you, I found that deleting the class and adding a new one with the same code worked.

answered Sep 19, 2022 at 16:06

David Pement's user avatar

In my case there was an old .iml file in the module causing these problems. So if nothing else worked for you, try looking for one.

answered Nov 22, 2022 at 10:08

Lenymm's user avatar

LenymmLenymm

8671 gold badge6 silver badges25 bronze badges

⬇ Download the last version of IntelliJ.

▶ Install it.

Worked for me. ✌

answered Jan 2 at 12:17

vvauban's user avatar

vvaubanvvauban

1095 silver badges8 bronze badges

following is code of my programme

Library.java
import coreservlets.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Library extends HttpServlet {

public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
String emailAddress = request.getParameter(«emailAddress»);//use to email&pass
String password = request.getParameter(«password»);//from html page

int a=LibraryStudent.findStudent(emailAddress, password);//to validate student
if (a=0) {
gotoPage(«/library/accounts.jsp», request, response);
}

student.setBookName(request.getParameter(«sname»));//use to sent other textbox
student.setBookName(request.getParameter(«bname»));//data in librarystudent
student.setDate(request.getParameter(«date»));//class after validation
HttpSession session = request.getSession(true);
session.putValue(«student», student);
//for moving different page
if (request.getParameter(«issue») != null) {
gotoPage(«/travel/issue.jsp»,
request, response);
} else if (request.getParameter(«sumbit») != null) {
gotoPage(«/travel/sumbit.jsp»,
request, response);
} else if (request.getParameter(«search») != null) {
gotoPage(«/travel/search.jsp»,
request, response);
} else if (request.getParameter(«account») != null) {
gotoPage(«/travel/EditAccounts.jsp»,
request, response);
} else {
gotoPage(«/travel/IllegalRequest.jsp»,
request, response);
}
}
private void gotoPage(String address,
HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher(address);
dispatcher.forward(request, response);
}
}
LibraryStudent.java
package coreservlets;
import java.util.*;
import java.text.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.util.*;

public class LibraryStudent {

private String emailAddress, password, sname,bname;
private String date,value;

public String getStudentName() {
return(sname);
}
public void setStudentName(String sname) {
this.sname = sname;
}
public String getEmailAddress() {
return(emailAddress);
}
public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}
public String getPassword() {
return(password);
}
public void setPassword(String password) {
this.password = password;
}

public String getBookName() {
return(bname);
}
public void setBookName(String bname) {
this.bname = bname;
}
public String getDate() {
return(date);
}
public void setDate(String date) {
this.date = date;
}
public String getIssueData() //method that create connection withh database
throws ServletException,IOException{
try{
getDate(); //and add a entry in database
getBookName();
getStudentName();
Class.forName(«sun.jdbc.odbc.JdbcOdbcDriver»);
Connection con=DriverManager.getConnection(«jdbc:odbc:db2»);
Statement st=con.createStatement();
String sql =
«insert into table1 (bookname,studentname,date) values(bname,sname,date)»;
st.executeUpdate(sql);
System.out.println(sql);

return «your book has been issued «;

}
catch(Exception e)
{
e.printStackTrace();
return «failed»;
}
}

public String getSumbitData()
throws ServletException,IOException{
try
{
getBookName();
getStudentName();
Class.forName(«sun.jdbc.odbc.JdbcOdbcDriver»);
Connection con=DriverManager.getConnection(«jdbc:odbc:db2»);
Statement st=con.createStatement();
String sql =
«delete from db2 where bookname=’bname’ and studentname=sname»;
st.executeUpdate(sql);
System.out.println(sql);

return «your book has been sumbitted «;
}
catch(Exception e)
{
e.printStackTrace();
return «failed»;
}
}

public static int findCustomer //to validate customer
(String emailAddress,
String password) throws ServletException,IOException{
try
{
if (emailAddress == null) {
return(0);
}
Class.forName(«sun.jdbc.odbc.JdbcOdbcDriver»);
Connection con=DriverManager.getConnection(«jdbc:odbc:user»);
Statement st=con.createStatement();
String sql=»select * from user where name='»+emailAddress+»‘ and password='»+password+»‘»;
System.out.println(sql);
ResultSet rs=st.executeQuery(sql);

if(rs.next())
return(1);
else
return(0);
}catch(Exception e)
{
e.printStackTrace();
return (0);}
}
}

and error is «Library.java:15: cannot access LibraryStudent
bad class file: .LibraryStudent.class
class file contains wrong class: coreservlets.LibraryStudent
Please remove or make sure it appears in the correct subdirectory of the classpa
th.
int a=LibraryStudent.findStudent(emailAddress, password);//to validate student
^
1 error» plz help me and tell how i run this project on server

thanks

Содержание

  1. bad class file error when it read class file .
  2. Comments
  3. bad class file error. Please help me
  4. Comments
  5. Bad Class File Error. What am i doing wrong?
  6. Comments

bad class file error when it read class file .

I got some very interesting problems.

I’ve got two source files:

package pack;
public class Hello
<
public static void fun(String[] args)
<
System.out.println(«Hello World!»);
>
>

class Use
<
public static void main(String[] args)
<
Hello.fun();
>
>

I compiled Hello.java using the command : javac -d . Hello.java
it worked well and I got the class file in the folder «pack» in the working directory.

In the working directory, I have Use.java, the folder «pack» that contains Hello.class and a folder «source» that contains «Hello.java».

when I try to compile Use.java, I get the following error:

Use.java:5: cannot find symbol
symbol : variable Hello
location: class Use
Hello.fun();
^
1 error

To clear this, I tried to use CLASSPATH environment variable to point to Hello.class that is present in the folder «pack».

to the existing CLASSPATH value of

Program FilesJavajre1.5.0_16librt.jar;D:Program FilesApache Software FoundationTomcat 5.5commonlibservlet-api.jar;.;D:oraclexeapporacleproduct10.2.0serverjdbclibojdbc14.jar

I added C:pack by the following command:

And then again I tried to compile Use.java without providing the import statement as

and I got the following error:

Use.java:5: cannot access Hello
bad class file: C:packHello.class
class file contains wrong class: pack.Hello
Please remove or make sure it appears in the correct subdirectory of the classpath.
Hello.fun();
^
1 error

Can anyone please help me out with this.

Here’s a tutorial on using packages [http://java.sun.com/docs/books/tutorial/java/package/index.html]

You have at least a couple of problems. (1) The Use class is in a different package from the Hello class. So you either need to «import pack.Hello;» or you need to refer to Hello with its fully qualified name like «pack.Hello.fun();» (2) You need the root directory of the package, not the .class file, in your classpath. If the current directory is in the classpath, and the ‘pack’ directory is in the current directory, then you do not need to do any additional classpath setting.

Thank you very much for the reply.

I want to explain.

I actually know that I have to import that class «Hello» or use the fully qualified name of Hello to use that in the class Use.java to use it.

I was just learning how the java compiler works . the hard way..

As you kindly pointed out in your second point, that I need not do any additional classpath setting if I have my «pack» directory in the current directory. I have the «pack» directory in the current directory.

I think it is making some difference in me adding the folder C:pack to the classpath than it without being added to the classpath as two DIFFERENT errors are being displayed during the compilation.

error . without specifying C:pack in the classpath:

Use.java:5: cannot find symbol
symbol : variable Hello
location: class Use
Hello.fun();

error when C:pack is specified in the classpath:

Use.java:5: cannot access Hello
bad class file: C:packHello.class
class file contains wrong class: pack.Hello
Please remove or make sure it appears in the correct subdirectory of the classpath.
Hello.fun();
*^*
*1 error*

If I did not remove the Hello.java file from my current directory, the java compiler tries to read the Hello.java file ‘thinking’ it to be the class file. and hence the «bad class file error» in this case.

But in my case, the java compiler is trying to read the class file that it actually needs here .. Hello.class but again showing that it is a bad class file.

Use.java:5: cannot access Hello
bad class file: C:packHello.class
class file contains wrong class: pack.Hello
Please remove or make sure it appears in the correct subdirectory of the classpath.
Hello.fun();
^
1 error

From what I have learnt of the java compiler, it searches for the class files in the following sequence:

1. ext folder of jre
2. the current working package
3. the packages that we specified in the import statements
4. the folders that are specified in classpath that are not already covered in the above three places

Источник

bad class file error. Please help me

I got a problem that is very strange. I have two source files saved in the same directory: E:Java Programmes

First one: A.java Second one: B.java I compiled these two files and got problem as follow:

*compiling file A.java is ok, no problem.
E:Java Programmes>javac -d «E:Java Programmes» A.java

*but got problem with B.java
E:Java Programmes>javac B.java
B.java:5: cannot access A
bad class file: .A.java
file does not contain class A
Please remove or make sure it appears in the correct subdirectory of the classpa
th.
A a = new A();
^
1 error

*The strange thing is that when i modify the file B.java as follow, it can run well
Output = Result: 8.

I keep wondering why it is like that. Because the statement «import util;*; » does not work well while the statement import «util.A ; » can work well. Please, anyone, explain it to me. Thannks a lot.

I compiled these two files and got problem as
follow:

*compiling file A.java is ok, no problem.
E:Java Programmes>javac -d «E:Java Programmes»
A.java

This should create E:Java ProgrammesutilA.class. Correct?

When you use «import util.*; » and the compiler finds a reference to a class named A, it does not know that you mean util.A class. It looks for A, finds the A.java file and tries to use it. When you use «import util.A; » it knows to look for a utilA.class or utilA.java file.

If you want to separate the source code files from the .class files, you should not have the source code files in the Classpath. If you have .java files in the Classpath, put them into the correct directory structure.

import.* is a way to tell the compiler that some of the references to classes in your code might be found in that package. When you have the javac compiler does not explicitly know that the class is util.A. It has to search through the Classpath directories to find a suitable .class or .java file. In your case, the Classpath includes E:Java Programmes. When the compiler looks in that directory, it apparently finds the A.java file before it finds the utilA.class file. The A.java is suitable as far as the compiler is concerned. It then tries to compile the source code, but when it does, it finds that the file contains util.A, not plain A as expected. The javac compiler is not smart enough to keep looking for a better .class or .java file.

When you use «import util.A;» the compiler knows that A.java is not suitable since it is not in a util directory.

If you move the A.java file into the util directory, you can make it work. Or, move the A.java file into a directory which is not in the Classpath.

javac searches the Classpath for a suitable .class file. By suitable, I mean that the file path relative to the Classpath matches the package name. All classes in Java have a fully qualified class name. The fully qualified name is the package name plus the class name. The .class file must reside in a directory structure matching the package name, relative to the Classpath.

In your case, the fully qualified class name is util.A. So somewhere on your computer (or in a jar file), there must be a directory named util and the A. class file must be in it. The util directory must be in a directory that is in the Classpath.tells javac to look inside e:Java Programmes when looking for classes and packages. For a class named util.A javac will look in E:Java Programmes for a util directory that contains A.class.

cut this and paste in your cmd prompt and then run your code..

(its javac [space] -d [space] . [space] A.java)

then you run your program.it ll work.

do reply if it works;)

Edited by: sanjay_gates on Oct 3, 2007 1:07 AM

It’s not likely that anyone will reply to a message that is 2 years old. Also, I’m not sure your solution would fix the problem.

Источник

Bad Class File Error. What am i doing wrong?

I am trying to run a ‘Hello World’ program which came with the FreeTTS package from links from the java.sun.com website, and am not able to compile the program. I get the error:

FreeTTSHelloWorld.java:4: cannot access
cl.com.sun.speech.freetts.audio.Voice
bad class file: .clcomsunspeechfreettsaudioVoice.class
class file contains wrong class: com.sun.speech.freetts.Voice
Please remove or make sure it appears in the correct subdirectory of the classpath.
import cl.com.sun.speech.freetts.audio.Voice;
_______________________________________^

The FreeTTSHelloWorld.java File is printed below [its embarassingly simple..]

/**
* Copyright 2001 Sun Microsystems, Inc.
**/
import cl.com.sun.speech.freetts.audio.Voice;
import cl.com.sun.speech.freetts.audio.JavaClipAudioPlayer;
import cl.com.sun.speech.freetts.en.us.CMULexicon;

public class FreeTTSHelloWorld <
public static void main(String[] args) <
try <
String voiceClassName = (args.length > 0) ? args[0] :
«com.sun.speech.freetts.en.us.CMUDiphoneVoice»;

Class voiceClass = Class.forName(voiceClassName);

Voice helloVoice = (Voice) voiceClass.newInstance();

helloVoice.speak
(«Thank you for giving me a voice. I’m so glad to say
hello to this world.»);

System.exit(0);
>
catch (Exception e) <
e.printStackTrace();
>
>
>

I’ve tried a billion things, including moving around the .class files [which, by the way, i extracted myself from the .jar files which came with the FreeTTS package — is that what i’m doing wrong? if so, please tell me — ] and still nothing happens — the same error results.

I’ve tried reading other cases similar to mine in the forums, but most of the things i read didn’t apply to my (quite simple) situation, such as the ‘package’ line needing to be removed or anything like that..

I run Win2k and have j2sdk1.4.0_01 installed on my machine

I beg for anyone’s help. Thanks in advance
-=Miagi=-

first make sure that the CLASSPATH environment variable points to the directory where the class files reside.
i.e.
if my java program has: and my class files reside in:
«c:My Java Classesameyerutil»
then my CLASSPATH variable should point to:
«c:My Java Classes»

another option is to leave the files in the jar and include the full path to the jar file in the class.
using the above example if I had all of my classes in a file called
Utilities.jar sitting in «C:My Java Classes»
then my CLASSPATH would be «C:My Java ClassesUtilities.jar»

also make sure that the import matches the directory structure
if I tried to use: it would not work.

hope this helps.

The error is not a class not found error.

Consequently it has nothing to do with the class path.

It specifically tells you what the problem is.

There are two components to this problem: the file and the class.

There is a file (not a class) like so

There is a class in that file called this.

Notice in the above that the file has «audio» in it. The class does not.

That means something is wrong.

The most likely problem is that you moved the file either intentionally or accidently. (You could even have two copies of the file.)

If this isn’t your code then some one else caused the problem.

The fix is to put the file in the right place. Or to change the package of the class (in the source code) and then recompile.

please leave the class files in the .jar-files, just add the .jar files to your classpath. That way you can’t mess around with directory structures among other things that makes the life of a ClassLoader difficult

Hey guys.
I have the exact same problem — but unfortunately your solution doesn’t work for me, because I believe my class is in the correct directory.

Here’s the error message:
Generated servlet error:
bad class file: C:TomcatwebappstestWEB-INFclassesjavabeansUserInfo.class
class file contains wrong class: UserInfo
Please remove or make sure it appears in the correct subdirectory of the classpath.
javabeans.UserInfo bean99 = null;

This occurs because of the following line in my index.jsp file:

The weird thing is, I’ve called many other bean files in the exact same directory — the following actually works fine:

My bean file is the world’s simplest file:
package javabeans;

public class UserInfo <
public String UserID=»»;
public String UserName=»»;
>

while other, more complicated files work fine.

any suggestions are helpful

Same problem, different reason.

Look at the original error from the first post.


bad class file: .clcomsunspeechfreettsaudioVoice.class
class file contains wrong class: com.sun.speech.freetts.Voice

Notice how the first part has a directory structure and a file name.
Notice how the second part has a package name which looks similar to the directory structure.

Now we look at your error.

The first part has a directory structure and a class file.
The second part has no package structure at all.

You have jar’d a file in a directory structure even though the class does not have a package. That doesn’t work.

Hi Everybody,
I have the same problem. When I try to compile HelloAgent.java, following error occurs:
C:kaaribogasource>javac org/kaariboga/agents/HelloAgent.java
org/kaariboga/agents/HelloAgent.java:41: cannot access org.kaariboga.agents.Histo
bad class file: .orgkaaribogaagentsHisto.class
class file contains wrong class: Histo
Please remove or make sure it appears in the correct subdirectory of the classpath.
Histo myApplet = new Histo();
^
1 error

HelloAgent code:
.
.
public void run() <
Histo myApplet = new Histo();
Frame myFrame = new Frame(«Work»);
myApplet.init();
myApplet.start();
myFrame.setSize(200,200);
myFrame.setLocation(100,100);
myFrame.add(myApplet, BorderLayout.CENTER);
myFrame.setVisible(true);

if (trips > 0) fireDestroyRequest();
>
.
.

Источник

Today We are Going To Solve java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment in Java. Here we will Discuss All Possible Solutions and How this error Occurs So let’s get started with this Article.

Contents

  • 1 How to Fix java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment Error?
    • 1.1 Solution 1 : switch to at least the 1.18.22
  • 2 Conclusion
    • 2.1 Also Read This Solutions
  1. How to Fix java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment Error?

    To Fix java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment Error just switch to at least the 1.18.22. You can solve this error very easily just by switching to at least the 1.18.22 version of Lombok. And your error will be solved. So try the below code for this: <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.22</version> </dependency>

  2. java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment

    To Fix java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment Error just switch to at least the 1.18.22. You can solve this error very easily just by switching to at least the 1.18.22 version of Lombok. And your error will be solved. So try the below code for this: <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.22</version> </dependency>

Solution 1 : switch to at least the 1.18.22

You can solve this error very easily just by switching to at least the 1.18.22 version of Lombok. And your error will be solved. So try the below code for this:

<dependency>
  <groupId>org.projectlombok</groupId>
  <artifactId>lombok</artifactId>
  <version>1.18.22</version>
</dependency>

Conclusion

So these were all possible solutions to this error. I hope your error has been solved by this article. In the comments, tell us which solution worked? If you liked our article, please share it on your social media and comment on your suggestions. Thank you.

Also Read This Solutions

  • Defaulting to user installation because normal site-packages is not writeable Python
  • This version of CLI is only compatible with Angular versions ^13.0.0, but Angular version 12.2.13 was found instead
  • Error: JavaFX runtime components are missing, and are required to run this application
  • ERROR: Could not build wheels for scipy which use PEP 517 and cannot be installed directly
  • npm WARN old lockfile The package-lock.json file was created with an old version of npm

To fix the “java.lang.IllegalAccessError: class lombok.javac.apt. LombokProcessor cannot access class com.sun.tools.javac.processing. JavacProcessingEnvironment” error in Java, there are several solutions we have tested that work. Follow the article to better understand.

What causes the error?

The error happens because you use the Lombok plugin to generate setters and getters for the area of ​​a particular category. I have the following solutions.

Use @Data( Lombok)

If you want to instantiate an Information class with full functions like getter, setter, toString, equals, hashCode and constructor, it will take a lot of time and cumbersome syntax. So I would suggest you use @Data to generate the above functions automatically during chapter building so you can optimize your time and focus on the more essential parts.

Example:

import lombok.Data;
@Data
public class Information {
    private String fullname;
    private Long id;
}

Update your Lombok

Lombok is a library in Java that automatically generates functions like setters/getters, constructors, and toString,…

The outstanding advantage of the Lombok library is that it helps to streamline the lengthy code of frequently repeated operations such as setters/getters and constructors to help programmers optimize working time.

If you get this error, please update your Lombok to at least version 1.18.20, so the program can run smoothly.

To use Lombok annotations, we add the Lombok dependency to pom.xml:

Example:

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.20</version>
    <scope>provided</scope>
</dependency>

Or you can download it at https://projectlombok.org/download.

Add Plugin to pom.xml

You can add Plugins to pom.xml able to resolve the error.

Example:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.1</version>
    <configuration>
        <source>16</source>
        <target>16</target>
        <!--                    <release>16</release>-->
        <fork>true</fork>
        <compilerArgs>
            <arg>--enable-preview</arg>
            <arg>-Xlint:all</arg>
            <arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
            <arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
            <arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
            <arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
            <arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</arg>
            <arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED</arg>
            <arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED</arg>
            <arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
            <arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
            <arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED</arg>
        </compilerArgs>
        <!--for unmappable characters in classes-->
        <encoding>UTF-8</encoding>
        <showDeprecation>true</showDeprecation>
        <showWarnings>true</showWarnings>
        <!--for lombok annotations to resolve-->
        <!--contradictory to maven, intelliJ fails with this-->
        <annotationProcessorPaths>
            <path>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.18.16</version>
            </path>
        </annotationProcessorPaths>
    </configuration>
</plugin>

Downgrade the current Java version

If you have installed the Lombok library and still get the “java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment” error, then I think you should downgrade your Java version. Maybe the error will be solved.

Summary

Please read this article if you encounter “java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment” in Java. If you have any questions about this issue, leave a comment below. I will answer your questions. Thanks for reading!

Maybe you are interested:

  • Error: Non-static Variable/Method ‘#’ Cannot be Referenced from a Static Context
  • Exception in Thread “Main” Java.util.nosuchelementexception
  • ERROR : ‘compileJava’ task (current target is 11) and ‘compileKotlin’ task (current target is 1.8) jvm target compatibility should be set to the same Java version in Java

Jason Wilson

My name is Jason Wilson, you can call me Jason. My major is information technology, and I am proficient in C++, Python, and Java. I hope my writings are useful to you while you study programming languages.


Name of the university: HHAU
Major: IT
Programming Languages: C++, Python, Java

Понравилась статья? Поделить с друзьями:
  • Java error bad operand types for binary operator
  • Java error a jni error has occurred please check your installation and try again
  • Java error 1723 при удалении java
  • Java error 1723 there is a problem with this windows installer package a dll
  • Java error 1608