Java applet does not call public static void main() anymore
Asked Answered
J

3

1

I have an applet that was originally built with JBuilder long time ago. I believe it worked fine until fairly recently. It has stopped working. I have imported it to Eclipse to debug, and found that public static void main() is not called. This can explain the applet's crash.

My hunch is that the newer JVM does not call public static void main() for applets. Could anyone shed some light on this?

Jerol answered 16/9, 2012 at 14:32 Comment(2)
Can you tell us which JVM you've tried?Argyrol
I believe the JRE I have on my computer is 1.7.0_07. I do not know exactly from which version this started to happen.Jerol
M
2

Java Applets require the applet lifecycle. There isn't any main for an applet.

Merbromin answered 16/9, 2012 at 14:36 Comment(5)
This means what we had in the old days - An Applet and Application - is not available anymore. heatonresearch.com/articles/18/page6.htmlJerol
Wow, I didn't know that. But AFAIK, it doesn't require one because the browsers can call an applet method, meaning main doesn't have to be the entry point. So if you press click on a new tab and go back to the tab with the applet, the applet calls start() and not init() (or main as it was)Merbromin
"what we had in the old days - An Applet and Application - is not available anymore." Rubbish. It is called an hybrid, and is alive and well. Ask on a separate question if you would like clarification.Wolfson
@AndrewThompson Can you explain here or add some links? I would like to know as well. ThanksMerbromin
@AndrewThompson I will ask now.Merbromin
Z
1

The main() method is normally used for applications. Any calls that you need to make at initialisation time should really be placed in:

public void init()

in your applet.

Zumstein answered 16/9, 2012 at 14:44 Comment(0)
F
1

My hunch is that the newer JVM does not call public static void main() for applets. Could anyone shed some light on this?

To my knowledge dating back to 1997, no VM has ever called main() for applets.

Fosterfosterage answered 17/9, 2012 at 3:18 Comment(1)
I think you are right. main() was created for the applet in case it is run as an application. I thought it was called because I noticed some initialization code (not automatically generated) in main. I have fixed the problem by importing the JBuilder project into Eclipse, replacing Applet with JApplet, and making a few other changes. I am not sure which step fixed the problem.Jerol

© 2022 - 2024 — McMap. All rights reserved.