Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 18 of 18

Thread: My code doesn't have a main clss?

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default My code doesn't have a main clss?

    I'm trying to designa simple Minecraft launcher GUI and it's not working with Netbeans.

    I made a video launcher for my University coursework and it works fine; I based the Minecraft launcher off of that code and Netbeans just isn't running the file.

    Here is the code I have (for the Minecraft launcher):

    import java.awt*;
    import java.awt.event*;
    import javax.swing*;

    public class MinecraftWiki extends JFrame implements ActionListener {
    JButton search = new JButton("Search");
    JButton open = new JButton("Enter the Minecraft Wiki");
    JButton close = new JButton("Exit");

    public static void main(String[] args) {
    new MinecraftWiki();

    }

    public MinecraftWiki() {
    setLayout(new BorderLayout());
    setSize(500, 500);
    setTitle("Minecraft Wiki");

    setDefaultCloseOperation(WindowConstants.DO_NOTHIN G_ON_CLOSE);

    JPanel bottom = new JPanel();
    bottom.add(search); open.addActionListener(this);
    bottom.add(open); open.addActionListener(this);
    bottom.add(close); open.addActionListener(this);

    setResizable(false);
    setVisible(true);

    }

    public void actionPerformed(Action Event e) {
    if (e.getSource() == search) {
    new CheckWiki();
    } else if (e.getSource() == quit) {
    System.exit(0);

    }
    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: My code doesn't have a main clss?

    Netbeans just isn't running the file.
    Please explain. Are there any errors? Copy them and paste them here.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: My code doesn't have a main clss?

    Have you made sure netbeans knows this is the main class it needs to run? Its in the project properties, under the "run" tab you can select which class you want netbeans to run. Or just try shift+F6 to run the main class whilst its open. Hope this is what you were looking for

  4. #4
    Junior Member
    Join Date
    Jan 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: My code doesn't have a main clss?

    Quote Originally Posted by Norm View Post
    Please explain. Are there any errors? Copy them and paste them here.
    This is the error that comes up:
    Exception in thread "main" java.lang.VerifyError: (class: MinecraftWiki, method: <init> signature: ()V) Constructor must call super() or this()
    Java Result: 1

    BUILD SUCCESSFUL (total time: 2 seconds)

    --- Update ---

    Quote Originally Posted by rossc View Post
    Have you made sure netbeans knows this is the main class it needs to run? Its in the project properties, under the "run" tab you can select which class you want netbeans to run. Or just try shift+F6 to run the main class whilst its open. Hope this is what you were looking for
    Yes, Netbeans knows.

    I always press F6 and go into the run tab.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: My code doesn't have a main clss?

    Is that all of the error message? Normal print outs of error messages give the location where the error happened.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Jan 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    F6 runs the project, shift+F6 runs the individual class/java file. But that's not your issue it's asking for a super method in the constructor I think judging on that error message, although I didn't think JFrame has anything to need to call super() let me just check...

  7. #7
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: My code doesn't have a main clss?

    Compile your code before you attempt to run it. What you posted won't compile and the compiler's message will be useful.

  8. #8
    Junior Member
    Join Date
    Jan 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Try adding super() as the first line in your constructor and just see if that works

  9. #9
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: My code doesn't have a main clss?

    Try...
    JFrame has a no-arg constructor.

    The problem here is that the code, as posted, will not compile. Consequently NB's verifier is going to grumble about whatever (old) class files it is looking at. The thing to do is to compile the code successfully (ie respond to the compiler's messages) before attempting to run it.

  10. #10
    Junior Member
    Join Date
    Jan 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: My code doesn't have a main clss?

    Quote Originally Posted by Norm View Post
    Is that all of the error message? Normal print outs of error messages give the location where the error happened.
    Here are some screenshots:
    p6Pgk.jpg

    dSkOL.png

  11. #11
    Junior Member
    Join Date
    Jan 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: My code doesn't have a main clss?

    Quote Originally Posted by pbrockway2 View Post
    JFrame has a no-arg constructor.

    The problem here is that the code, as posted, will not compile. Consequently NB's verifier is going to grumble about whatever (old) class files it is looking at. The thing to do is to compile the code successfully (ie respond to the compiler's messages) before attempting to run it.
    I was never taught how to compile a piece of code... I don't think.

    How do you do that?

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: My code doesn't have a main clss?

    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: My code doesn't have a main clss?

    Those red squiggly things in the screen shots are compiler messages indicating a problem with the code. They all have to be fixed, which is not has hard as it might seem.

    I agree with Norm, if you can't coax a reasonable description of the problem(s) out of NB, compile your code at the command line. If the Tutorial instructions don't make sense, post back and say what you've done and what happened. The compiler will produce a *lot* of output: one for each red squiggled line. That's normal. Deal with whatever you can and post whatever remains here, and I'm sure someone can explain what each means so you can fix it.

  14. #14
    Junior Member
    Join Date
    Jan 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Have you import the correct packages?

  15. #15
    Junior Member
    Join Date
    Jan 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: My code doesn't have a main clss?

    Quote Originally Posted by pbrockway2 View Post
    Those red squiggly things in the screen shots are compiler messages indicating a problem with the code. They all have to be fixed, which is not has hard as it might seem.

    I agree with Norm, if you can't coax a reasonable description of the problem(s) out of NB, compile your code at the command line. If the Tutorial instructions don't make sense, post back and say what you've done and what happened. The compiler will produce a *lot* of output: one for each red squiggled line. That's normal. Deal with whatever you can and post whatever remains here, and I'm sure someone can explain what each means so you can fix it.
    Ok, I'll look at the tutorial now

    --- Update ---

    Quote Originally Posted by rossc View Post
    Have you import the correct packages?
    Yes

    --- Update ---

    I tried to compile the code in Netbeans, but it says I've already compiled it.

    I read the tutorials but I can't see my JDK 7 platform

  16. #16
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: My code doesn't have a main clss?

    I read the tutorials but I can't see my JDK 7 platform
    The link Norm provided only requires you to choose your operating system. It is written with JDK 7 in mind.

  17. #17
    Junior Member
    Join Date
    Nov 2012
    Posts
    14
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default Re: My code doesn't have a main clss?

    errors::
    1.you missed "." while importing
    ex:import java.awt.*;
    2.please check the parameters of setDefaultyCloseOperation
    its DO_NOTHING_ON_CLOSE
    3.parameter of actionPerformed()
    its ActionEvent (no space between them)
    4.finally..you don't have any variable as "exit"
    its "close" i assume

    and considering you have written the class CheckWiki()

    thats all of the errors in your code
    Last edited by rougeking; January 11th, 2013 at 03:33 PM. Reason: Please don't spooonfeed code

  18. #18
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default offtopic

    @rougeking: thanks for removing the code. My first thought when I see something full of typos is to say "Here, do it like this..." but I'm convinced of the futility of this approach as it demonstrates what would be right but doesn't address question of what was wrong. Since similar problems are *certain* to occur again, an understanding of what was wrong is much more valuable.

    In the OP's case, he or she still has to deal with NB's perverse willingness to attempt to run defective code and the consequent very cryptic runtime messages. Also there's the basic question of what compilation is and how you compile. The Tutorial link addresses exactly that.

    A little point but when you do post code the appropriate tags have square brackets: [code] ... [/code]

Similar Threads

  1. actionListner code doesn't work ????
    By sciences in forum AWT / Java Swing
    Replies: 4
    Last Post: February 27th, 2012, 06:46 AM
  2. Code compiles fine but doesn't run Properly
    By nadirkhan in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 9th, 2011, 12:46 PM
  3. File Reading code doesn't work
    By koryvandell in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 25th, 2011, 08:40 AM
  4. Code doesn't execute properly
    By fride360 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 12th, 2011, 12:36 PM
  5. Can someone please tell me why my code doesn't print out anything?
    By deeerek in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 6th, 2010, 08:35 AM

Tags for this Thread