I am student currently trying to make a game in java. However I can't seem to run the project with the IDEA IDE. I am getting the message: "Exception in thread "main" java.lang.ClassNotFoundException: kamikaas.game.World" But when I look at the class structure I can't see why it wouldn't find the class. You can see the class structure and message here
It is probably an entry point issue. Make sure you set the entry point to your main class (the class with main method).
After you edit: As I guessed, your World class doesn't have a main method. You have to start your project with the correct class.
Ok, got a working project now, I added Maven to my project and it fixed my problem. As for the entry point suggestion, I have looked numerous times and it was correct. I don't know what the cause was but I don't care if it doesn't exist anymore.
Related
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.
I have defined two classes for a java program I am writing, call them Class1 and Class2. In the body of the constructor for Class1, I call the constructor for class 2. However, I am getting the compile error
"The type of Class1(JSONObject) is erroneous".
I tried googling this error but could not find any discussion of this exact error anywhere, so I thought I would post it to stack exchange.
Could someone please explain what type of error this is? Both class1 and class2 are very simple: both have only a constructor method, which takes a JSONObject as an argument in both cases. The only imports are for JSON. Any advice?
//class1 definition
public class Class1 {
public Class1(JSONObject jObject){
try{
//parsing json and saving class variables
} catch(Exception e)
{
System.out.println("Class1 JSON Exception: " + e.getMessage());
}
}
}
//constructor of Class2
Class1 user;
public Class2(JSONObject jObject){
try{
JSONObject userJSON = jObject.getJSONObject("user");
user = new Class1(userJSON); //error occurrs here
}
catch(Exception e){
System.out.println("Class2 JSON Exception: " + e.getMessage());
}
}
}
EDIT: when I try to run the code even with this compile error, I get the following runtime error:
Exception in thread "main" java.lang.ExceptionInInitializerError
at bitcoin.thesis.Client.main(BTCJamClient.java:18)
Caused by: java.lang.RuntimeException: Uncompilable source code - Erroneous tree type:
thesis.JSONArray
at thesis.Class3.<clinit>(Class3.java)
... 1 more
Java Result: 1
Class3 here is another class that has a default constructor. Client is the main class which takes the http request and passes the JSON object to Class2 constructor. Basically this is the part of the code execution before Class1 and Class2 constructors are even called. So it is not caused directly by the compile error, but I suspect they are related to the same problem that has do do more generally with my coding environment.
Thanks,
Paul
I would have preferred to leave this as a comment but as I do not have the reputation I couldn't. I realise this is also a very late response but don't know if you have found the answer or not. I came across this while googling for an answer myself.
I also believe that this error is unrelated to the code but is rather an error created by NetBeans. I found the same code compiled and ran fine in NetBeans on one machine but not the on the other where I had first encountered the error.
The solution for me was to close NetBeans, clear the NetBeans cache and restart NetBeans.
I was using version 8.0 and the location of the cache for me is:
~/.cache/netbeans/8.0/
I deleted everything in the folder and on the next run everything was fine.
For older versions I believe the cache may be in a different location which can be found by opening the about window from the help menu.
Make sure that you have entered correct package names in your classes.
I had the same issue and the solution was very simple in my case.
The case:
I copy/paste some classes from another project in a package of the project I am working in.
Some of them had the old package declaration and the compiler didn't complained (for his reasons).
When I used a method with return type one of the 'wrong packaged' classes this error appeared.
(The Type of is erroneous)
The solution
To solve the issue, I changed the package declaration to be the correct one!
I got the same issue and fixed using the excepted answer, as I'm using windows 10 so here is the cache folder location:
C:\Users\USER_NAME\AppData\Local\NetBeans\Cache\8.1
AppData is a hidden folder.
I had the same issue on netbeans 8.0. The following trick should fix it:
Right click on the project -> properties -> build -> compiling ==> uncheck "compile on save" then click ok
I faced this issue. I solved it by adding all dependent jars to the project/file
Grease's answer re deleting the contents of netbeans cache works. I'm using Netbeans 8.1 on MacOS Sierra.
Deleted everything under "/Users//Library/Caches/NetBeans/8.1/"
This is an addition to the answer of Grease. (I can't add a comment due to lack of reputation.)
I sometimes run into the same issue and always deleted the complete folder, so NetBeans had to rebuild the maven-stuff which can take a few minutes.
If someone uses maven and don't want NetBeans has to completely rebuild the maven repos and -index, don't delete the following folders in the NetBeans cache folder:
index
mavencachedirs
mavenindex
Just tested it with NetBeans 11.3:
Not deleting the three folders makes the error(s) go away but don't bothers maven.
I could imagine that this is the same with older versions of NetBeans.
I decided to stop/restart NetBeans 8.2 before taking the "nuclear" approach. The error was gone when I got back in.
I am new to Java and started with Eclipse Kepler Service Release 1. I started a small project that contains two classes, each in its own file:
MIDI_Wrap_Test - a main (program) class
MIDI_Wrap - another class (MIDI_Wrap) which is intended as a MIDI wrapper. -
Both classes are in the same directory with file names being the same as the class name (with .java added of course). Something goes wrong and I want to debug it. However, when control transfers from the main program to the MIDI_Wrap file/class I get the error message 'source not found'.
I found out that this is a quite common error. The question and answer that seem to mirror my problem perfectly is found here. I added the project to the debug source path, noticing that the correct directories were already added but to no avail.
I must be doing something wrong but am not able to find out what. Can someone help me out of this?
I solved by shutting down eclipse and reopened it. This solved me, and code can be debug with source code view.
I've searched in previous posts but cant seem to find the solution, my code worked perfectly until i did something wrong , and now i get "Error: Could not find or load main class gaming.Game"
I think i might have deleted something in the eclipse configurations, How can i solve this?
Your title's error does not match the one you wrote in your question.
The "simon.Game" says that the Game class is in a package called simon. The other error you posted says that it's inside gaming package. This is important.
You can go into eclipse's run configuration and point to the correct class that has the main method.
With eclipse, it is sometimes necessary to remove a project and re-import it in order to solve problems like this. When removing the project, be sure not to leave "delete project contents on disk" checked.
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.