Results 1 to 4 of 4
  1. #1
    ruud00000 is offline Member
    Join Date
    Dec 2010
    Rep Power

    Question Netbeans versus JavaEditor: main class?

    I created several small applets and classes, in separate directories, using JavaEditor, which run fine (also using JavaEditor: Applet Viewer) or running the .html file in a webbrowser. If I try to run the same applets in NetBeans (6.9) however I get the error message 'no main class found'. Indeed I have no classes with the name 'main', but in JavaEditor that is not an issue? I do however have a method init() in each applet, as I learned that an applet should have such a method. Can I instruct NetBeans to look for an init() method instead of a main() method?

    I imported the files in the directory containing the original source files into a NetBeans Project, set the Project as the Main project.

    All I want is to start editing my existing java source code in NetBeans instead of JavaEditor. Should I make changes to the source code in order to be able to make that switch?
    Last edited by ruud00000; 01-08-2011 at 10:02 PM.

  2. #2
    Jodokus's Avatar
    Jodokus is offline Senior Member
    Join Date
    Jan 2011
    Amsterdam, the Netherlands
    Rep Power


    I don't think is has anything to do with the editors (IDE's). Applets need a class extending JApplet (or Applet, long time ago) having a method init(), (and more, but init will mostly do). Seems you figured this out.
    If the IDE is complaining about a main class it's looking for a method main(), not a class Main. That's when somehow you try to start your program as a standalone application, the other way Java is often used (not embedded in a webpage). I don't know NetBeans (using Eclipse) but that should be easy to find.
    (It's a very basic question, try to find some introduction.) Succes!

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power


    I would guess that the problem is that you have
    several small applets and classes
    in your NetBeans project, so the IDE doesn't know which you want to run.

    Luckily for you, NetBeans comes extensive on-line help; search for 'set main class' and you should find what you need to do to fix that.

    If you don't know how to open on-line help, ask.


  4. #4
    ruud00000 is offline Member
    Join Date
    Dec 2010
    Rep Power


    OK thanks. I found I can run the applets by right clicking on the applet source file itself and choose 'Run'. The normal run button only works for an application, not for an applet... I could not find this in the Netbeans Help documentation, that is apparently all based on building standalone applications, telling how to set a main class etc but that's not what I was looking for.

    This is unlike the Javaeditor, where the run button simply (compiles and) runs, no matter if the app is an applet or a standalone aplication.

Similar Threads

  1. Running main method class from another main class
    By tlrocketman in forum New To Java
    Replies: 3
    Last Post: 12-06-2010, 09:30 AM
  2. Replies: 7
    Last Post: 09-08-2010, 10:50 AM
  3. Java versus VBA
    By waspandbee in forum New To Java
    Replies: 8
    Last Post: 06-14-2010, 12:21 PM
  4. different multiple public class and main class
    By mr idiot in forum New To Java
    Replies: 2
    Last Post: 01-01-2009, 01:10 PM
  5. How to create main class link to another two class?
    By pearllymary78 in forum New To Java
    Replies: 6
    Last Post: 07-16-2008, 11:02 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts