Unable to config and run a Java project in IntelliJ - java

Me and a few other students are building a game with Java at university. Someone else setup the basic structure for the project and i pulled the repo and tried to run it.
When i run it i get
this window
When i open the config, i am unable to add the main class, it is located in the file shown in the image. The OK button is disabled. You can see that here.
I'm running the latest version of IntelliJ, JDK 9 and Windows 10. The project in question is built with LibGDX. The full repo and folder structure can be seen here.
I am able to setup my own project and run my own apps, i just can't run this specific project.
Please help.

I think, since you have no "Java" directory, Intellij does not recognize any folder as Java Sources. You'll have to do that manually by rightclicking and mark the desired directory as Source root.

I figured out what the problem was, and of course - it was obvious. The project was setup with an old version of Gradle (2.4) and i was running Java 9. I installed Java 8 and made the project run.
The OK button was disabled because the project hadn't built properly (i though it had) so it couldn't find the class i needed to run it.

Related

Cannot run project - the selection cannot be launched and there are no recent lanuches

i have following problem:
Yesterday i worked on my selenium&maven project in java on eclipse and after work i export project as archive, today i want to import whole project and run it on second computer, but i receive 'the selection cannot be launched and there are no recent lanuches'.
I tried run configuration, but there's no effect.
My archive is available here: https://drive.google.com/open?id=1BB0tqege1iWE_qdbHSEhfvNuFqPa8SO7 or https://github.com/mtpx/af/tree/master/automationFramework
How can I execute this project?
It using Selenium, Maven and TestNG, so there's no main class here
Maybe the project you have in hands was not exported properly, missing important metadata for the compiler.
Make sure the project is being correctly exported using (right click) export option and not only copy+paste/zip+share.

Cannot load or find main class, works in command line but not in IDE's [duplicate]

This question already has answers here:
Gradle - Could not find or load main class
(16 answers)
Eclipse "Error: Could not find or load main class"
(61 answers)
Closed 4 years ago.
Before you mark this as a duplicate, please hear me out.
I am trying to import a java project with gradle(Fully functional, works for every other laptop with no issues).
My project is 100% functional, it works on every other laptop
This issue started when my laptop was reimaged an set as windows 10
I have configure the Environment variables, JAVA_HOME = C:\Program Files\Java\jdk1.8.0_161, in PATH I've added C:\Program Files\Java\jre1.8.0_161\bin
Command line I am seeing the correct version. (Java -version)
I right clicked my project "configure build path". I ensured that it is the latest version I mentioned in my environment variable (1.8.0_161).
I've imported my project, clean build, refreshed and ran (shows Cannot find or load main class)
In the command line, I did gradle clean build builds successfully with no error
I also ran my java application java -jar app.jar My applications starts up and runs on localhost:8080
I created a test project a simple hello world, and it is running with no issues.
So, My question stands what is causing this cannot load main class error in ECLIPSE and in Spring tools suite IDE?
PS: I do not have any misconfigure packages(as I mentioned project works perfectly find on any other laptop)
Also, I have deleted Eclipse(.p2, .eclipse, eclipse and eclipse workspace folder), Java, and gradle and reinstalled all of the multiple times.
UPDATE
As mentioned above (#8) it will work if I run the .jar application.
I also tried running my java application thru command prompt
java C://.......myMainApp.java
Error: Could not find or load main class com.jesse.umsswap.app.myMainApp
Edit not duplicated
As I mentioned in this post, The two links provided by Jarrod did not resolve my issue. I have gone thru those two post and the solutions did not solve mine.
PS
Have you ever had a working java project in git, but when you cloned it is saying "cannot load or find main class"?
If ./gradlew clean build gives no errors, the resulting jar can be run successfully and your Gradle wrapper is fine (see question comments for more info), maybe reimporting the project to eclipse (as a Gradle project, -> buildship) may result in finding the main class
My thoughts: You ensured that your gradle build is working and other gradle projects within the same worksace are functional too. Then the next logical step is to work with a fresh copy of your project: Re-import it.
After closing eclipse delete all eclipse related files (.settings, bin, .classpath, .project) as well as the run configuration you used to start the application. Make sure you back it up or know all infos to recreate it (vm args, environment vars for your run config).
I know this is an invasive step, but if you say other fresh eclipse projects work, why not make your project a fresh one too?

Stuck with first time java for android

guys, with my friend started working on a school project - developing a java app for android. He started it, now it's my turn to do my job, so i got the code he already has, set up Android SDK for Eclipse and downloaded all the neccessary files and packages, but it still gives me errors and I can't even run the project.
One of the errors (the main one, I think) is that it can't import android.support.v7.app.ActionBarActivity
If anyone knows what can I do (I've tried all kinds of solutions from the internet, but none work) I would be very grateful.
Here is a screenshot of the code
http://s17.postimg.org/8aw952lha/Capture.jpg
See if you have imported the ActionBar project to your Eclipse workspace, also, right click on your project->properties->android and check that you have referenced/linked the ActionBar project there.
If you are using a repository without the proper ignore files it is possible that you have imported your partners configurations and then have the references to the auxiliary projects broken (you just need to update that).
Hope it helps.
android.support.v7.app.ActionBarActivity is a support library. This allows older versions of Android (before native support for an action bar was available) to use the action bar.
Since you are having difficulty importing it, I'd assume you do not have the support library installed.
Full instructions are available here:
http://developer.android.com/tools/support-library/setup.html
A snippet for adding support libraries to Eclipse:
Make sure you have downloaded the Android Support Library using the SDK Manager.
Create a libs/ directory in the root of your application project.
Copy the JAR file from your Android SDK installation directory (e.g., /extras/android/support/v4/android-support-v4.jar) into your application's project libs/ directory.
Right click the JAR file and select Build Path > Add to Build Path.

Issues with Eclipse while working on and Android project

I am currently developing an application with my software engineering classmates. I am experiencing a few issues with Eclipse, however. But first, some information about my Eclipse: I am running version: Juno Service Release 2 with a build id of 20130225-0426. I am running Eclipse on my MacBook with OS X Mountain Lion 10.7.5. I am using SVN to upload and download the project to a repository through assembla.com.
First, Eclipse will not recognize any errors. If I purposely type random characters, Eclipse does not underline them with red.
Next, whenever I type "this.whatever" or "# for javadoc" I receive the following message: "this compilation unit is not on the build path of a Java project." I can click "OK" and continue with no problem though.
Finally, whenever I attempt to run the program I receive this message:"The selection cannot be launched, and there are no recent launches."
Other notes: I do not have any of these issues with any of my other projects in my workspace. I also have another project using the assembla repository that does not contain these issues. These issues just occurred all of the sudden.
Edit: None of the other members in my group are experiencing these issues. I have attempted to download the project from the repository on a different machine and I still have these problems. I have attempted to delete the project from my workspace and re-download. Still a no go.
Update: I even installed the Android Development Kit and used the included copy of Eclipse. It will still not work properly.
What is going on with my Eclipse?
Since I guess you're in start phase of android coding and you're not addicted to a special IDE, I strongly recommend the IntelliJ IDEA instead of Eclipse for Android development. I have tried Eclipse already and because of its weaknesses, now I'm using IntelliJ. Eclipse is not the best IDE for Android development and have a long way to become the one.
IntelliJ IDEA
I suggest you try installing the ADT bundle in a new location and see if you still have these problems. The ADT bundle includes the latest Android SDK along with a version of Eclipse with the ADT (the Android Developer Tools plugin) already installed and configured. It's possible that you have (or have had in the past) other Eclipse plugins that affect how the Java tools in Eclipse work, possibly in a way that interferes with ADT. I have personally had problems like this in the past with tools like Aptana, where even after uninstalling there would be problems.
Eclipse is telling you already with the above error message: You don't have your sources on a build path, but just in some folder.
Either you have created a simple project instead of a Java project, which then also doesn't do anything Java specific. Or you have created your Java files in plain folders, instead of source folders.
The best way to sort this out is to create a new Java project using the Eclipse "New..." wizard from the main menu. Compare the result of that to your project. The two important things are: The project has an icon with a small "J" overlayed. The Java sources are shown in packages, which themself are in source folders (with a package overlay), not in simple folders.

Unable to run Java program in Eclipse Juno 4.2

I reinstall my Eclipse environment every year when the new version is released. The most recent release - Juno - however, does not work as expected.
Currently, when I try running demos from Oracle, for example, it asks me to select an Ant file to run before compiling. After creating a blank Ant file to bypass the requirement (which I thought was rather dumb, since I don't think TDD is something that should be forced on people), it still refused to run, saying the "Selection could not be launched."
I understand that Juno is an update from the 3.x track to the 4.x track, but this seems a little ridiculous to me. What can or should I do so I can get Eclipse back up and running again?
Just to clarify:
All files in question are on my Eclipse workspace path
I don't do much in the way of Java development, though I know I'll need to do so soon. Hence, my unfamiliarity with the most recent version of Eclipse.
I would like to run my files & projects without Ant files. I know it has something to do with Run configs, but I don't know how to change them.
Here's what I did to run the demo from Eclipse Juno:
Downloaded the project from http://docs.oracle.com/javase/tutorial/uiswing/examples/zipfiles/components-FrameDemoProject.zip (if this is not the correct demo, then please provide the link you're using)
Unzipped it to my projects directory (not my workspace), so that you have:
PROJECTS_DIR/components-FrameDemoProject/src
PROJECTS_DIR/components-FrameDemoProject/nbproject
PROJECTS_DIR/components-FrameDemoProject/build.xml
From Eclipse, File > New > Java Project
List item Uncheck Use default location and navigate to <PROJECTS_DIR>/components-FrameDemoProject
Hit Finish
Drill down to src/components/FrameDemo.java
Right-click on FrameDemo.java and select Run As > Java Application
Let me know if any of these steps give you trouble.
Take a look at you project properties and select the Builders entry. Do you see an Ant Builder entry? Try to select or create a Java Builder entry instead.
I just created a new Java Project in Juno and added the FrameDemo.java source. In my case, the Java Builder was selected as the default for this new project.

Categories