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);
}
}
}
Re: My code doesn't have a main clss?
Quote:
Netbeans just isn't running the file.
Please explain. Are there any errors? Copy them and paste them here.
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
Re: My code doesn't have a main clss?
Quote:
Originally Posted by
Norm
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
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.
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.
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.
Re: My code doesn't have a main clss?
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.
2 Attachment(s)
Re: My code doesn't have a main clss?
Quote:
Originally Posted by
Norm
Is that all of the error message? Normal print outs of error messages give the location where the error happened.
Here are some screenshots:
Attachment 1694
Attachment 1695
Re: My code doesn't have a main clss?
Quote:
Originally Posted by
pbrockway2
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?
Re: My code doesn't have a main clss?
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.
Re: My code doesn't have a main clss?
Quote:
Originally Posted by
pbrockway2
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
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
Re: My code doesn't have a main clss?
Quote:
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.
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