I have a class which extends OrmliteSqliteOpenHelper in order to provide a persistence module for an Android application. The problem is, whenever I access this class from the test project in Eclipse, it throws a NoClassDefFound Exception. The source code appears to be fine as the package is imported and Eclipse has no highlighting to indicate anything will go wrong, but it does.
Here's the kicker: not only does everything else in the project work fine when accessed from the test project, but when I move this file into the test project voila it works perfectly! The issue is that it needs to be in the actual project in order for other components to make calls to it. Has anyone ever encountered this error or have any idea where I might be going wrong?
The class path is set correctly as all the other classes work and the test project always has the main project added to its class path. I also tried moving the OrmliteSqliteOpenHelper object to an inner class: this allowed the outer class to be visible and touched but as soon as it tried to instantiate the inner class the same error occurs. Also, if I copy this file into both projects in the same package, an error occurs stating "class ref in pre-verified class resolved to unexpected implementation" whenever something in the main project tries to access this class. Clearly, there is some difference in the way the class is being compiled/handled between the two projects.
I'm quite stumped :/ Thanks a ton for any assistance!
Well friends, I seem to have hacked together a solution for this issue:
I linked the entire 'src' folder from the main project into the one for the test project. Now, when it goes searching for the particular package my file is located in, it finds the file in its own source tree first. Hooray!
Why does this work? I haven't a clue, perhaps someone could enlighten us to that fact.
Does it work? For now...
There is how I fix the problem:
Remove OrmLite from Build Path of the test project.
Export them from the main project.
Related
Error:Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:
Without any class list it's giving error
I'm developing library. In that I created one class and used it in demo app importing. When I instantiate object of that class then it compiles successfully. But when I try to access getter methods at next line then it gives above error.
I'm not understanding where it's going wrong, because it does not showing any class name or error location.
Can any one help??
#Pamela Hill had the right answer, if you hover over the error on the left you'll see that there's more, and you can copy this into a text editor to see it the full output.
I've been using Eclipse for a while and I'm having trouble understanding what's going on with my first project in IntelliJ. I've read the documentation, and searched other questions, but I still can't seem to grasp it. I think there is something wrong with my project structure. This is what my structure currently looks like;
I'm trying to run the JavaForLoop class, but whenever I do, compilation fails because I have errors in the StringMethods class of the strings package. My question is why would that prevent compilation if the two classes are in separate packages? Neither class uses the other, and they both have the appropriate package declaration statements. With a similar structure in Eclipse, this would work. Should I be using a different project structure?
By default IDEA adds Build Configuration which is executed before launch and includes following steps (taken from here):
Compiling source code in the source path of a module and placing results to the output path.
Compiling source code in the test path of a module and placing results to the test output path.
Creating copies of the resource files in the output path.
Reporting problems in the Messages tool window.
check if it's your case in Edit Configuration screen and if so, remove it.
To use a class from a different package you must declare a import statement to the class.
In your JavaForLoop.java add the import before the class statement (and after package declaration where its the case)
//package ...
import strings.StringMethods;
//public class JavaForLoop { and the rest of the code
Intellij uses regular javac, which will fail to compile if you have errors anywhere in the code.
Eclipse has it's own compiler, that allows to compile and even run code that has compilation errors, causing a runtime exception if any part of the code that has errors is run. This allows you to run parts of the code that work even if other pieces of code are failing.
The simple solution is to resolve your compilation errors. You can also use the eclipse compiler with Intellij, but I've never done this so I can't comment on how well it works.
After moving to maven, whole my project glitched and randomly throws java.lang.NoClassDefFoundError for classes. I discovered that once I refactor the package with that class to something else, like blahblahblah and then back to original name, the glitch is gone.
I have these packages:
cz.autoclient.autoclick
cz.autoclient.autoclick.comvis
I had to refactor cz.autoclient.autoclick because of this error:
Exception in thread "Thread-2" java.lang.NoClassDefFoundError: cz/autoclient/autoclick/ColorPixel
But when I wanted to refactor it back from blahblah to cz.autoclient.autoclick, netbeans won't let me do that:
Here's a picture. You can see that standalone cz.autoclient.autoclick doesn't exist:
I must say that I'm becoming really angry about this consistent problem and the way my IDE hadnles it. During rage-refactoring I also noticed that netbeans is capable of concurently refactoring files with the result of two names being messed up together. Like aublahtocliblahck.
How can I now convince netbeans that to create the original package for me?
After googling for a while, I discovered quick fix:
Enable full tree view for project explorer
Now, the top level package containing sub-packages will bee seen and you can drag'n'drop the class files from blahblah package.
Here is another way to get classes to the right package:
select the classes you want to move
right-click
refactor → move
Alternatively, simply select the classes and press Ctrl + M.
Firstly, I know that similar questions have been asked and answered before, however none of the solutions worked in my case.
For some reason, eclipse keeps showing a launch error saying that no main method is found despite there being a public static void main(String[] args) in my main class. Could there be an issue in the class path? I'm really unsure whats causing it.
Try putting your java files under the "src" folder. Apparently they are all out of that folder and that could be the cause.
Go to Run->Run Configurations, select your project. In the Main tab, for Main class, give class name along with complete path of the class containing main function. This worked for me :)
Try to say at the beginning of the code:
package yourpackage; //<----------your package is the name of the
package you are in
The class havent automatically put the package comment at the beginning of the Code
because like the other say your structure is false.
Yours:
project -----> classes,src
Should be:
project ---->src ---->package----> class
I got the same error but with different reason. I changed my java build path libraries to 15.0.1 and tried to run and it failed after that I changed them back to 11.0.2 and it worked.
I have a listener program that triggers a main program based on the below conditions
If the database has new records
If the time from last run is 10 minutes.
This is done using ScheduledExecutorService of Java (https://stackoverflow.com/a/26043250/1930402 helped out).
So, I am calling a perfectly working program from this Listener, located in another Project and another Folder. That is, I am calling project B from project A. To enable this, I added a dependency of Project B in Project A's POM.xml.
There is an error in one of the classes of Project B, and it is NoSuchMethodError. I can see the method right there. From the answers of this post, https://stackoverflow.com/a/24902026/1930402, I understand that this particular class might not be there in my build path. I am not sure of this.
Can anyone advise?
Note: Project B runs without any issues when it is run independently.
Java Doc tells:
"Normally, this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed."
How can the definition of my class change while running using a static instance?
This is my stack:
java.lang.NoSuchMethodError:a.b.c.StringUtils.formatDateToString(Ljava/lang/Object;)Ljava/lang/String;
So, these are the key points: Maven Dependency, ScheduledExecutorService, Static Class.
The reason for the error was that same class names and same package names were present in Project A and Project B and a set of other projects which were being used. Once I made each of them unique, things started working fine.