-
Help with NoSuchMethodError:
hey guys new java programmer (hopefully) looking for a little guideness here.
if just cannot get any program to run off of JCreator to run at all, even the samples that come with the program or source code from the net.
everytime it loads fine untill in the Dos window (for lack of me knowing a better word) i get "Exception in thread "main" java.lang.NoSuchMethodError: main
Press any key to continue...
Heres the code:
import java.awt.*;
import java.awt.event.*;
public class MyFirstFrame extends Frame {
public MyFirstFrame() {
MenuBar menuBar = new MenuBar();
Menu menuFile = new Menu();
MenuItem menuFileExit = new MenuItem();
menuFile.setLabel("File");
menuFileExit.setLabel("Exit");
// Add action listener.for the menu button
menuFileExit.addActionListener
(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
MyFirstFrame.this.windowClosed();
}
}
);
menuFile.add(menuFileExit);
menuBar.add(menuFile);
setTitle("MyFirst");
setMenuBar(menuBar);
setSize(new Dimension(400, 400));
// Add window listener.
this.addWindowListener
(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
MyFirstFrame.this.windowClosed();
}
}
);
}
protected void windowClosed() {
System.exit(0);
}
}
Could use any help you wise sages could give thx.
-
Well don't be scared
that's because any standalone application need a main method in one of class in the code ;
it will not run without such a mothod
it goes
public static void main(string[] lalama){
// your instructions here
}
try again good line
-
that's should work let me know
import java.awt.*;
import java.awt.event.*;
public class MyFirstFrame extends Frame {
public MyFirstFrame() {
MenuBar menuBar = new MenuBar();
Menu menuFile = new Menu();
MenuItem menuFileExit = new MenuItem();
menuFile.setLabel("File");
menuFileExit.setLabel("Exit");
// Add action listener.for the menu button
menuFileExit.addActionListener
(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
MyFirstFrame.this.windowClosed();
}
}
);
menuFile.add(menuFileExit);
menuBar.add(menuFile);
setTitle("MyFirst");
setMenuBar(menuBar);
setSize(new Dimension(400, 400));
// Add window listener.
this.addWindowListener
(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
MyFirstFrame.this.windowClosed();
}
}
);
}
protected void windowClosed() {
System.exit(0);
}
/* that's all you needed to add to your nice code lol*/
public static void main(String[] lalama){
MyFirstFrame windo=new MyFirstFrame();
windo.show();
}
}
-
thx alot man works great. really appreciate the help. now off to get stumpted some more! thx
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|