Error: "Could not find or load main class" in my project

42 views
Skip to first unread message

P5music

unread,
Feb 2, 2021, 6:19:57 AM2/2/21
to CodenameOne Discussions
So I restored my project but now I get the issue that led to break it in the first place by messing with .idea folder (bad StackOverflow advice).

"C:\Program Files\Java\jdk-11.0.2\bin\java.exe" "" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.3.2\lib\idea_rt.jar=51275:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.3.2\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\user\sviluppo\myapp\out\production\myapp;C:\Users\user\sviluppo\myapp\src;C:\Users\user\sviluppo\myapp\lib\CodenameOne.jar;C:\Users\user\sviluppo\myapp\JavaSE.jar;native\internal_tmp;lib\impl\cls com.codename1.impl.javase.Simulator com.myapp.app.myapp
Error: Could not find or load main class 
Caused by: java.lang.ClassNotFoundException: 

Process finished with exit code 1

The project was in fact recreated and the source files copied, so it is possible that the main class setting was lost.
I set the src folder as source folder but the issue still persists.

The iml file seems to have correct entries and so do the xml's in the .idea folder. See below.
But
manifest.mf says
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

see also the manifest below.

What is to be done in order to fix the issue?
Thanks in advance

codename_settings.properties

baseClass=src/generated/StateMachineBase.java
codename1.android.keystore=
codename1.android.keystoreAlias=
codename1.android.keystorePassword=
codename1.arg.ios.newStorageLocation=true
codename1.arg.java.version=8
codename1.displayName=MyApp
codename1.icon=icon.png
codename1.ios.appid=Q5GHSKAL2F.com.myapp.app
codename1.ios.certificate=
codename1.ios.certificatePassword=
codename1.ios.debug.certificate=
codename1.ios.debug.certificatePassword=
codename1.ios.debug.provision=
codename1.ios.provision=
codename1.ios.release.certificate=
codename1.ios.release.certificatePassword=
codename1.ios.release.provision=
codename1.j2me.nativeTheme=nbproject/nativej2me.res
codename1.languageLevel=5
codename1.mainName=MyApp
codename1.packageName=com.myapp.app
codename1.rim.certificatePassword=
codename1.rim.signtoolCsk=
codename1.rim.signtoolDb=
codename1.secondaryTitle=MyApp
codename1.vendor=CodenameOne
codename1.version=1.0
guiResource=theme.res
mainForm=Main
package=generated
userClass=src/userclasses/StateMachine.java


myapp.iml
<?xml version="1.0" encoding="UTF-8"?>
<module type="CodenameOne.Module" version="4">
  <component name="NewModuleRootManager" inherit-compiler-output="true">
    <exclude-output />
    <content url="file://$MODULE_DIR$">
      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
    </content>
    <orderEntry type="jdk" jdkName="11" jdkType="JavaSDK" />
    <orderEntry type="sourceFolder" forTests="false" />
    <orderEntry type="library" scope="PROVIDED" name="Codename One Libraries" level="project" />
  </component>
</module>

ant
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="AntConfiguration">
    <buildFile url="file://$PROJECT_DIR$/build.xml" />
  </component>
</project>

misc
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="11" project-jdk-type="JavaSDK">
    <output url="file://$PROJECT_DIR$/out" />
  </component>
</project>

modules
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="ProjectModuleManager">
    <modules>
      <module fileurl="file://$PROJECT_DIR$/myapp.iml" filepath="$PROJECT_DIR$/myapp.iml" />
    </modules>
  </component>
</project>

Shai Almog

unread,
Feb 2, 2021, 9:50:07 PM2/2/21
to CodenameOne Discussions
In the settings you have::
codename1.mainName=MyApp
codename1.packageName=com.myapp.app

But intellij is running
Simulator com.myapp.app.myapp

Notice the case difference. It should be either MyApp or myapp but that should be consistent everywhere.
Message has been deleted

P5music

unread,
Feb 3, 2021, 10:01:36 AM2/3/21
to CodenameOne Discussions
Sorry, maybe that was a wrong string replacement of mine I think.

I think that the problem was that the line
codename1.description=Myapp app
that was missing.
Now it seems to be working...

No, the issue shows up again.

This time indeed I have to remove that line to be able to run again.
And then I have to restore it...and remove...

But not all the times. It seems that every now and then the main class setting is lost somewhere and editing that line fixes it  (or maybe just editing the file, I cannot check it now).

It is very strange. Maybe you understand what's happening. 
It seems that editing and saving that file is necessary every time the main class is lost (why is it lost?).
Regards

Shai Almog

unread,
Feb 3, 2021, 9:48:36 PM2/3/21
to CodenameOne Discussions
I have never heard of the main getting lost in that file. I have no idea how that can happen.

P5music

unread,
Feb 4, 2021, 4:57:21 AM2/4/21
to CodenameOne Discussions
Maybe it is happening elsewhere and this is just a strange "reset" procedure.
What you know about what could cause the main class to be lost, so to fix it properly?
Regards

Shai Almog

unread,
Feb 5, 2021, 1:03:09 AM2/5/21
to CodenameOne Discussions
I have no idea.

P5music

unread,
Feb 5, 2021, 8:33:57 AM2/5/21
to CodenameOne Discussions
However what also happens is that the launch instructions are different just by the presence of a "" amid the string, whenever the main class is lost:

<pre>
"C:\Program Files\Android\jdk\microsoft_dist_openjdk_1.8.0.25\bin\java.exe" "" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.3.2\lib\idea_rt.jar=63780:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.3.2\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\User\sviluppo\myapp\out\production\myapp;C:\Users\User\sviluppo\myapp\src;C:\Users\User\sviluppo\myapp\lib\CodenameOne.jar;C:\Users\User\sviluppo\myapp\JavaSE.jar;native\internal_tmp;lib\impl\cls com.codename1.impl.javase.Simulator com.myapp.app.MyApp

"C:\Program Files\Android\jdk\microsoft_dist_openjdk_1.8.0.25\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.3.2\lib\idea_rt.jar=59088:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.3.2\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\User\sviluppo\myapp\out\production\myapp;C:\Users\User\sviluppo\myapp\src;C:\Users\User\sviluppo\myapp\lib\CodenameOne.jar;C:\Users\User\sviluppo\myapp\JavaSE.jar;native\internal_tmp;lib\impl\cls com.codename1.impl.javase.Simulator com.myapp.app.MyApp
</pre>

I can also run the line without that "" and it works without having to edit the settings file.
Regards

Shai Almog

unread,
Feb 6, 2021, 12:55:59 AM2/6/21
to CodenameOne Discussions
Where did that additional "" come from?
Reply all
Reply to author
Forward
0 new messages