Unable to modify the Java codes - java

I am new to Java and I found something super weird. I imported a project into my eclipse and tried to made some changes to it.
However, no matter what I did the output of the project remained the same even after I commented out the entire Main class.
Anyone has a clue why this is happening ?

It's likely that your project cannot built due to some critical problem (missing required library, unable to write to the output directory, etc.). Please check "Errors/Warnings" view, there should be some hint.

Looks like you had compiled classes in the target directory. Do a Project > Clean before you run.

Related

Cannot resolve corresponding jni function

i read a lot of posts but cannot resolve this yet.
There is my error lines and structure of project:
Some libraries and configs I take from another project... And don't know where I went wrong.
I will give you source code of files if needed
Thank you for any help.
I've also been getting this error since upgrading from Android Studio 2 to 3. The code compiles, but the IDE isn't recognizing the native functions. (This may be due to a preprocessor macro I've created that simplifies JNI function names.)
I've suppressed this error in Java by adding #SuppressWarnings("JniMissingFunction") before my class declaration.
Ok, so this missing 'JNI function' isn't a big deal. I know it's highlighted red, but the function is being linked, just not in a way that the IDE can determine.
First, here's the relevant source code: https://github.com/koreader/crengine/blob/master/android/jni/cr3engine.cpp#L770
CrEngine is linking the functions at run time. The reason why your IDE isn't picking them up is because the CrEngine functions start with Java_org_ instead of Java_com_. If you were relying on the engine to automatically link, this would be an issue, but as stated before, they are being explicitly linked at runtime with jniRegisterNativeMethods.
Do a clean and update your build tools to 25.0.3 (or better) in your gradle.build file. Update your SDKs and NDK. Then rebuild. Some of the errors I saw could be caused by older build tools.

Package not detected after renamed in Intellij

I have a project in intellij and when I created my packages I made a mistake because they all start in capital letter, for example my previous package name was "Main" then I changed it to "main" and I did it to all of my packages.
error: package com.myproject.thesis.main does not exist import
com.myproject.thesis.main.Main;
but the "main" package and "Main" class does exist and already imported on the class that needs it. Also what should I name the package where I put my main class?
While it may not help in this case, a general thing to try when "My code compiles and runs, but IDEA is really confused about the symbols in my project" is to go into the "File" menu and choose "Invalidate Caches / Restart". I've rarely used it, and it doesn't always help, but every once in a while it fixes IDEA's confusion.
See also the IntelliJ IDEA help on Cleaning System Cache.
You need to edit configuration. From IntelliJ Run menu choose Edit Configurations. On the configuration window change the package name of Main class.
I hope this helps.
Try changing the packages to something else first. e.g. coma.myprojecta.thesisa.maina and get that to work. Then change it back to com.myproject.thesis.main. I think IntelliJ might be having problems with the change in case. If you change it something totally different and then back it IntelliJ should realise that things have changed.
As for what to call the class with main method, it is up to you. There is some good advice here. https://softwareengineering.stackexchange.com/questions/208062/naming-conventions-for-java-classes-that-have-a-static-main-method
You could also try a complete reset of the project. Create a whole new project, with the packages named (and cased) the way you want. Then, move the code files from your old project into the folders for your new project. IDEA should be able to see the files you put in there and parse them correctly.
Just clean the contents in /target (or "mvn clean"), and Intellij can find your new package correctly.

Could not find or load main class Swing Java

Error: Could not find or load main class jewelleryerpapplication.GUI.ERPMainMenu
Java Result: 1
Actually i am using Net Beans 7.1 and in that i am continuosly getting the same error but un able to get the solution for that even after installing the latest update for that. The solution which i got from some body that create new project and copy the source and library foldes in that Project from the previous which generate the above error. this solution works for me but i need some simpler solution for this problem.Lot of thanks in advance.
Don't Forget To Give UpVote It If It Helps.
Right click on project node, go to Set configuration, select the main class for your application. Then clean and build.
Even if this doesn't solve your problem, then delete the Netbeans cache by deleting the (index) folder
User\.netbeans\6.9\var\cache\index\
I think that the following is happening:
If this is a third party application, you have not included some jar files on your class path;
Or, (which in my opinion is the most likely) you do not have a method which has this signature: public static void main(String[] args). This method defines the main entry point for your application, not having it might cause that error when you try and run the project. To my knowledge, Netbeans creates a main class with such a method automatically whenever you create a new project. This might be the reason why you are not having this exception when you create a new Project and throw everything in it.
You might be having an issue with Netbeans itself. You can start by either checkin gout this previous SO thread in which a similar (I think) issue is being discussed, or else, as a final resort, you might want to remove Netbeans and all its files, and install an earlier version. You can also try and see if you get the same issue if you use a different IDE such as Eclipse.
the solution is,right click your package in netbeans,go to properties,source now go to the jre option and choose your version,the programme will now run.

Eclipse ClassNotFoundException

Everything works fined, but suddenly eclipse stopped execute and junit tests or even main method, when i run them using run as - > Java application, run as -> junit test
It simply throws error
Caused by: java.lang.ClassNotFoundException: package.ClassName
whene ClassName - is class from where i trying to run method main.
It affect only one of my projects ... Different workspaces works fine, other project in same workspace works fine as well.
I'm sure if i recreate current project, error will gone. But the adjustments of this project in eclipse is really hard, so i want to avoid it.
Any clue?
The ClassName is not in the Class Path, if you start from console you should use -cp parameter , if from eclipse, please add ClassName to the sources of current(start) project.
Thanks to adarshr, I was able to look at the Problems window and determine that the build was failing because it could not find a class I had written.
I had used the MS TFS plugin to create a "shelveset" and it was supposed to have removed my pending changes in the process. However, this integration with the TFS snapin and Eclipse is obviously not well implemented, since the Eclipse project still thought the file existed and was complaining that it could not be compiled.
I went and manually deleted those "files" or "non-existing files" from the Eclipse project (that I thought I had removed with the shelveset action) and the problem was solved.
Also....
Another annoying things is that the Tomcat error I was getting by trying to debug within Eclipse was like this:
SEVERE: Error configuring application listener of class
com.CompanyName.ProjectName.servlet.StartupConfigListener
java.lang.ClassNotFoundException:
com.CompanyName.ProjectName.servlet.StartupConfigListener at
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1643)
In reality, there was no problem at all with StartupConfigListener.java!! The build failed due to the OTHER problems I mentioned above, and therefore I guess this was the first class it attempted to load and failed.... because the entire project hadn't been able to compile perhaps?
(Here's to hoping my next project is using Visual Studio instead of Eclipse!)
Ok, I finally figured it out. The problem was with installed JRE in eclipse setting. I was playing around with this setting and changed installed JRE to JDK, and for some reason it broke the eclipse project.
You can also try going back to the basics. Check your command line and VM args. I've had this situation where a VM arg I was passing in was a path to a file that had a space in the path, and I had forgotten to include the full path in quotes. So e.g., if my arg looked something like
-DFILE=C:\Documents and Settings\myfile
...I'd get a java.lang.NoClassDefFoundError caused by a java.lang.ClassNotFoundException.

m2eclipse marking 'target' directory as 'Derived'

I have a Maven Java project, imported using m2eclipse.
The target/ directory is not marked as 'Derived' by m2eclipse.
Problems:
It is validated, so any validation error appear twice. My example shows a JSP Problem, when I insert intentionally an error in a jsp.
When I want to open a resource with Ctrl-Shift-R, all files appear twice, and I run the risk of editing the copy instead of the original file.
Possibly see post eclipse-ignore-folder
Note: When I set manually the directory to derived, the validation problem doesn't disappear, so that would only be part of the solution...
Question:
Is there something I need to do, so that m2eclipse sets the target/ directory to 'Derived' ?
Yeah, that has been around for a while. I wrote a plug-in that allows you to mark directories as "derived" without having to find them all (http://eclipsefrills.sourceforge.net/). It's not great, and you still have to manually run the action to make it work, but it may help.
Odd, though, I have not noticed the problem lately, myself. I wonder if there is some setting in the preferences that takes care of this now.
Good luck.
I got rid of this problem by writing a custom plug-in KeepTargetDerivedPlugin. As its name suggests, it automatically keeps all target folders derived (unlike the other solutions, which require user action).
Still, e. g. the YA2O's plug-in can be used to mark derived folders of projects which already reside in the given Eclipse workspace.
Yes: open a bug report :)
I have been so annoyed by this problem that I wrote a plugin to solve it. You can get the source and jar from here.

Categories