IntelliJ unable to run the class/compiled class

My problem is not being able to run the core.DTNSim because intelliJ said that some methods are undefined. Weirdly, I already set the project source to src directory, then setting the run config's output directory to the same one i compiled the project (target). The run does not want to run. I'm not sure what other informations I can provide, but it is all in the picture.
No description
29 Replies
JavaBot
JavaBot6d ago
This post has been reserved for your question.
Hey @circle! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
circle
circleOP6d ago
As seen from the error, it couldn't find the class DTNSimGUI even though it is within the project and is compiled properly. It's ONE simulator project btw
JavaBot
JavaBot6d ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
dan1st
dan1st6d ago
Can you show that class in the src folder? as well as the content of the file as text it's pretty hard to read stuff in your screenshot
circle
circleOP6d ago
@echo off
setlocal EnableDelayedExpansion

:: Configuration variables
set "targetdir=target"
set "libdir=lib"
set "mainclass=core.DTNSim"
set "memory=512M"
:: ^ Modify the memory limit as needed, 512 is kinda low for dtnsim lol, but
:: this is here to not let dtnsim to hog resources when you want to multitask

echo [INFO] Starting DTNSim...

:: Validate target directory exists
if NOT EXIST "%targetdir%" (
echo [ERROR] Target directory '%targetdir%' not found. Did you compile the project?
echo [INFO] Try running compile.bat first.
exit /b 1
)

:: Build classpath from all JAR files
echo [INFO] Building classpath...
set "CLASSPATH=%targetdir%"

:: Check if lib directory exists
if NOT EXIST "%libdir%" (
echo [WARNING] Library directory '%libdir%' not found. Continuing without external libraries.
) else (
for %%f in (%libdir%\*.jar) do (
echo !CLASSPATH! | findstr /C:"%%f" >nul || set "CLASSPATH=!CLASSPATH!;%%f"
)
)

:: Run the application with all parameters passed to this script
echo [INFO] Running with memory limit: %memory%
echo [INFO] Classpath: %CLASSPATH%
echo [INFO] Main class: %mainclass%

java -Xmx%memory% -cp "%CLASSPATH%" %mainclass% %*

:: Check if Java executed successfully
if %ERRORLEVEL% NEQ 0 (
echo [ERROR] Execution failed with error code %ERRORLEVEL%.
exit /b %ERRORLEVEL%
) else (
echo [INFO] Execution completed successfully.
)

endlocal
@echo off
setlocal EnableDelayedExpansion

:: Configuration variables
set "targetdir=target"
set "libdir=lib"
set "mainclass=core.DTNSim"
set "memory=512M"
:: ^ Modify the memory limit as needed, 512 is kinda low for dtnsim lol, but
:: this is here to not let dtnsim to hog resources when you want to multitask

echo [INFO] Starting DTNSim...

:: Validate target directory exists
if NOT EXIST "%targetdir%" (
echo [ERROR] Target directory '%targetdir%' not found. Did you compile the project?
echo [INFO] Try running compile.bat first.
exit /b 1
)

:: Build classpath from all JAR files
echo [INFO] Building classpath...
set "CLASSPATH=%targetdir%"

:: Check if lib directory exists
if NOT EXIST "%libdir%" (
echo [WARNING] Library directory '%libdir%' not found. Continuing without external libraries.
) else (
for %%f in (%libdir%\*.jar) do (
echo !CLASSPATH! | findstr /C:"%%f" >nul || set "CLASSPATH=!CLASSPATH!;%%f"
)
)

:: Run the application with all parameters passed to this script
echo [INFO] Running with memory limit: %memory%
echo [INFO] Classpath: %CLASSPATH%
echo [INFO] Main class: %mainclass%

java -Xmx%memory% -cp "%CLASSPATH%" %mainclass% %*

:: Check if Java executed successfully
if %ERRORLEVEL% NEQ 0 (
echo [ERROR] Execution failed with error code %ERRORLEVEL%.
exit /b %ERRORLEVEL%
) else (
echo [INFO] Execution completed successfully.
)

endlocal
I usually use this batch file to run the program instead of utilizing IntelliJ (it's an old framework), so it works normal without the running config
circle
circleOP6d ago
This is the whole structure and the run configuration
No description
No description
dan1st
dan1st6d ago
Does the error occur with the run configuration or with the batch script?
circle
circleOP6d ago
run configuration! I'm so not used on using the built in run configurations for these pure java stuffs... no maven/gradle sadly
dan1st
dan1st6d ago
Are you using a build tool (Maven/Gradle)? ah ok
circle
circleOP6d ago
Not on this project, it's an older framework
dan1st
dan1st6d ago
When running the project, it has a line like java --enable-preview ... at the top cna you copy that line?
circle
circleOP6d ago
A friend's version of the program does work, but it's much more outdated and simplified- This one is pretty modifeid but I haven't had the time to compare (a lot of differences) oh yeah here
"C:\Program Files\Java\jdk-21\bin\java.exe" --enable-preview "-javaagent:C:\Users\narwa\AppData\Local\Programs\IntelliJ IDEA Ultimate\lib\idea_rt.jar=58112" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath D:\Development\Java\jarkom22-onesim-archive\target\production\jarkom22-onesim-archive;D:\Development\Java\jarkom22-onesim-archive\lib\fastjson-1.2.7.jar;D:\Development\Java\jarkom22-onesim-archive\lib\lombok.jar;D:\Development\Java\jarkom22-onesim-archive\lib\junit-4.10.jar;D:\Development\Java\jarkom22-onesim-archive\lib\jFuzzyLogic.jar;D:\Development\Java\jarkom22-onesim-archive\lib\junit-4.10-extended-1.0.4.jar;D:\Development\Java\jarkom22-onesim-archive\lib\uncommons-maths-1.2.1.jar;D:\Development\Java\jarkom22-onesim-archive\lib\ECLA.jar;D:\Development\Java\jarkom22-onesim-archive\lib\DTNConsoleConnection.jar core.DTNSim
Exception in thread "main" java.lang.NoClassDefFoundError: gui/DTNSimGUI
at core.DTNSim.main(DTNSim.java:116)
Caused by: java.lang.ClassNotFoundException: gui.DTNSimGUI
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
... 1 more
"C:\Program Files\Java\jdk-21\bin\java.exe" --enable-preview "-javaagent:C:\Users\narwa\AppData\Local\Programs\IntelliJ IDEA Ultimate\lib\idea_rt.jar=58112" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath D:\Development\Java\jarkom22-onesim-archive\target\production\jarkom22-onesim-archive;D:\Development\Java\jarkom22-onesim-archive\lib\fastjson-1.2.7.jar;D:\Development\Java\jarkom22-onesim-archive\lib\lombok.jar;D:\Development\Java\jarkom22-onesim-archive\lib\junit-4.10.jar;D:\Development\Java\jarkom22-onesim-archive\lib\jFuzzyLogic.jar;D:\Development\Java\jarkom22-onesim-archive\lib\junit-4.10-extended-1.0.4.jar;D:\Development\Java\jarkom22-onesim-archive\lib\uncommons-maths-1.2.1.jar;D:\Development\Java\jarkom22-onesim-archive\lib\ECLA.jar;D:\Development\Java\jarkom22-onesim-archive\lib\DTNConsoleConnection.jar core.DTNSim
Exception in thread "main" java.lang.NoClassDefFoundError: gui/DTNSimGUI
at core.DTNSim.main(DTNSim.java:116)
Caused by: java.lang.ClassNotFoundException: gui.DTNSimGUI
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
... 1 more
OH wait i think i saw it? after target\, it points to production?
dan1st
dan1st6d ago
it does seem to expect the compiled classes in D:\Development\Java\jarkom22-onesim-archive\target\production\jarkom22-onesim-archive How did you create the run configuration?
circle
circleOP6d ago
this and the project structure outpuot here
dan1st
dan1st6d ago
That's showing the run configuration but now how you created it
circle
circleOP6d ago
I did it by: 1. Opening run configurations 2. Clicking + sign to add 3. Choosing "Application"
No description
No description
circle
circleOP6d ago
i think it's all it is. Havent tried to use the Batch option (for step 3)
dan1st
dan1st6d ago
What is shown in "Modify options"?
circle
circleOP6d ago
No description
circle
circleOP6d ago
II... I might've just solved it?
dan1st
dan1st6d ago
by creating a new run configuration?
circle
circleOP6d ago
What I just did was checking the "Modify Classpath", then added the target folder (literally the target) folder
No description
circle
circleOP6d ago
and it just runs :idontunderstand: d
circle
circleOP6d ago
No description
dan1st
dan1st6d ago
ok
circle
circleOP6d ago
Aight, seems to be solved now. Thank you so much! I overlooked the part where you told me this
JavaBot
JavaBot6d ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
JavaBot
JavaBot6d ago
Post Closed
This post has been closed by <@389034898666553344>.

Did you find this page helpful?