java.lang.NoSuchMethodError: main
Exception in thread "main"
Process completed.
(I made a main method)
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.
java.lang.NoSuchMethodError: main
Exception in thread "main"
Process completed.
(I made a main method)
You're going to have to post the actual code (in the form of an SSCCE), exactly how you're trying to run it, and the exact error message. Java does not see a main method in whatever class you're trying to run.
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
Maltese (July 3rd, 2012)
package GUI;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class Testing extends JPanel implements MouseListener{
private JTextField textField;
private JButton button;
public Testing(){
super.setLayout(new BorderLayout());
this.build();
}
public void build(){
JPanel center = new JPanel(new FlowLayout(FlowLayout.CENTER));
super.add(center, BorderLayout.CENTER);
textField = new JTextField();
center.add(textField);
this.button = new JButton("On-Screen Keyboard");
button.setSize(new Dimension(200, 20));
center.add(button);
button.addMouseListener(this);
}
public void mouseClicked(MouseEvent e)
{
if (e.getSource() == button)
{
CharacterPadSpace b = new CharacterPadSpace(textField);
}
}
public void mouseEntered(MouseEvent e)
{
// if (e.getSource() == a){ System.out.println("Test1");}
}
public void mouseExited(MouseEvent e)
{
//if (e.getSource() == a){ System.out.println("Test1");}
}
public void mousePressed(MouseEvent e)
{
//if (e.getSource() == a){ System.out.println("Test1");}
}
public void mouseReleased(MouseEvent e)
{
//i/f (e.getSource() == a){ System.out.println("Test1");}
}
public static void main (String [] args)
{
JFrame f = new JFrame();
f.setLocation(50, 50);
f.setSize(470, 500);
f.setVisible(true);
Testing m = new Testing();
f.add(m);
}
}
/**
* @(#)CharacterPadSpace.java
*
*
* @Jamie
* @version 1.00 2012/6/3
*/
package GUI;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class CharacterPadSpace extends JFrame implements MouseListener
{
private JButton a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, space, bspace, capsLock;
private JTextField myTextField;
private JButton zero, one, two, three, four, five, six, seven, eight, nine;
private boolean capsPressed = false;
public CharacterPadSpace(JTextField myTextField)
{
super.setLayout(new BorderLayout());
this.myTextField = new JTextField("");
super.setPreferredSize(new Dimension(200,500));
this.myTextField = myTextField;
super.setLocation(50, 50);
super.setSize(470, 500);
super.setVisible(true);
this.build();
}
public void build()
{
JPanel north = new JPanel(new FlowLayout(FlowLayout.CENTER));
super.add(north, BorderLayout.NORTH);
north.setBorder(BorderFactory.createEmptyBorder(20 , 0, 0, 0));
JPanel center = new JPanel(new GridBagLayout());
super.add(center, BorderLayout.CENTER);
center.setBackground(new Color(255, 255, 240));
JPanel south = new JPanel();
super.add(south, BorderLayout.SOUTH);
south.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
JPanel east = new JPanel();
super.add(east, BorderLayout.EAST);
east.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
JPanel west = new JPanel();
super.add(west, BorderLayout.WEST);
west.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
GridBagConstraints cc = new GridBagConstraints();
a = new JButton("a");
a.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc.ipadx = 20;
cc.ipady = 20;
cc.insets = new Insets(0,3,0,3);
cc.gridx = 0;
cc.gridy = 0;
center.add(a, cc);
b = new JButton("b");
b.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc.weightx = 0.5;
cc.insets = new Insets(0,0,0,3);
cc.gridx = 1;
cc.gridy = 0;
center.add(b, cc);
c = new JButton("c");
c.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc.insets = new Insets(0,0,0,3);
cc.weightx = 0.5;
cc.gridx = 2;
cc.gridy = 0;
center.add(c, cc);
d = new JButton("d");
d.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc.weightx = 0.5;
cc.insets = new Insets(0,0,0,3);
cc.gridx = 3;
cc.gridy = 0;
center.add(d, cc);
e = new JButton("e");
e.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc.weightx = 0.5;
cc.insets = new Insets(0,0,0,3);
cc.gridx = 4;
cc.gridy = 0;
center.add(e, cc);
bspace = new JButton("<----");
bspace.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc.weightx = 0.5;
cc.gridwidth = 2;
cc.insets = new Insets(0,3,0,3);
cc.fill = GridBagConstraints.HORIZONTAL;
cc.gridx = 5;
cc.gridy = 0;
center.add(bspace, cc);
GridBagConstraints cc2 = new GridBagConstraints();
cc2.ipadx = 20;
cc2.ipady = 20;
f = new JButton("f");
f.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc2.weightx = 0.5;
cc2.insets = new Insets(4,3,0,0);
cc2.gridx = 0;
cc2.gridy = 1;
center.add(f, cc2);
g = new JButton("g");
g.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc2.weightx = 0.5;
cc2.insets = new Insets(4,0,0,3);
cc2.gridx = 1;
cc2.gridy = 1;
center.add(g, cc2);
h = new JButton("h");
h.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc2.weightx = 0.5;
cc2.insets = new Insets(4,0,0,3);
cc2.gridx = 2;
cc2.gridy = 1;
center.add(h, cc2);
i = new JButton("i");
i.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc2.weightx = 0.5;
cc2.insets = new Insets(4,0,0,3);
cc2.gridx = 3;
cc2.gridy = 1;
center.add(i, cc2);
j = new JButton("j");
j.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc2.weightx = 0.5;
cc2.insets = new Insets(4,0,0,3);
cc2.gridx = 4;
cc2.gridy = 1;
center.add(j, cc2);
k = new JButton("k");
k.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc2.weightx = 0.5;
cc2.insets = new Insets(4,0,0,3);
cc2.gridx = 5;
cc2.gridy = 1;
center.add(k, cc2);
l = new JButton("l");
l.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc2.weightx = 0.5;
cc2.insets = new Insets(4,0,0,3);
cc2.gridx = 6;
cc2.gridy = 1;
center.add(l, cc2);
m = new JButton("m");
m.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc2.weightx = 1;
cc2.insets = new Insets(4,3,0,3);
cc2.gridx = 0;
cc2.gridy = 2;
center.add(m, cc2);
n = new JButton("n");
n.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc2.weightx = 0.5;
cc2.insets = new Insets(4,0,0,3);
cc2.gridx = 1;
cc2.gridy = 2;
center.add(n, cc2);
o = new JButton("o");
o.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc2.weightx = 0.5;
cc2.insets = new Insets(4,0,0,3);
cc2.gridx = 2;
cc2.gridy = 2;
center.add(o, cc2);
p = new JButton("p");
p.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc2.weightx = 0.5;
cc2.insets = new Insets(4,0,0,3);
cc2.gridx = 3;
cc2.gridy = 2;
center.add(p, cc2);
q = new JButton("q");
q.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc2.weightx = 0.5;
cc2.insets = new Insets(4,0,0,3);
cc2.gridx = 4;
cc2.gridy = 2;
center.add(q, cc2);
r = new JButton("r");
r.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc2.weightx = 0.5;
cc2.insets = new Insets(4,0,0,3);
cc2.gridx = 5;
cc2.gridy = 2;
center.add(r, cc2);
s = new JButton("s");
s.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc2.weightx = 0.5;
cc2.insets = new Insets(4,0,0,3);
cc2.gridx = 6;
cc2.gridy = 2;
center.add(s, cc2);
t = new JButton("t");
t.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc2.weightx = 0.5;
cc2.insets = new Insets(4,3,0,3);
cc2.gridx = 0;
cc2.gridy = 3;
center.add(t, cc2);
u = new JButton("u");
u.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc2.weightx = 0.5;
cc2.insets = new Insets(4,0,0,3);
cc2.gridx = 1;
cc2.gridy = 3;
center.add(u, cc2);
v = new JButton("v");
v.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc2.weightx = 0.5;
cc2.insets = new Insets(4,0,0,3);
cc2.gridx = 2;
cc2.gridy = 3;
center.add(v, cc2);
w = new JButton("w");
w.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc2.weightx = 0.5;
cc2.insets = new Insets(4,0,0,3);
cc2.gridx = 3;
cc2.gridy = 3;
center.add(w, cc2);
x = new JButton("x");
x.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc2.weightx = 0.5;
cc2.insets = new Insets(4,0,0,3);
cc2.gridx = 4;
cc2.gridy = 3;
center.add(x, cc2);
y = new JButton("y");
y.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc2.weightx = 0.5;
cc2.insets = new Insets(4,0,0,3);
cc2.gridx = 5;
cc2.gridy = 3;
center.add(y, cc2);
z = new JButton("z");
z.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc2.weightx = 0.5;
cc2.insets = new Insets(4,0,0,3);
cc2.gridx = 6;
cc2.gridy = 3;
center.add(z, cc2);
capsLock = new JButton("caps lock");
capsLock.setFont(new Font("Lucida Sans Regular", Font.ITALIC, 18));
cc2.gridwidth = 2;
cc2.gridheight = 2;
cc2.weightx = 0.5;
cc2.insets = new Insets(4,3,0,3);
cc2.gridx = 0;
cc2.gridy = 4;
cc2.ipadx = 40;
cc2.ipady = 81;
center.add(capsLock, cc2);
zero = new JButton("0");
zero.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc2.gridwidth = 1;
cc2.gridheight = 1;
cc2.weightx = 0.5;
cc2.insets = new Insets(4,0,0,3);
cc2.gridx = 2;
cc2.gridy = 4;
cc2.ipadx = 20;
cc2.ipady = 20;
center.add(zero, cc2);
one = new JButton("1");
one.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc2.weightx = 0.5;
cc2.insets = new Insets(4,0,0,3);
cc2.gridx = 3;
cc2.gridy = 4;
center.add(one, cc2);
two = new JButton("2");
two.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc2.weightx = 0.5;
cc2.insets = new Insets(4,0,0,3);
cc2.gridx = 4;
cc2.gridy = 4;
center.add(two, cc2);
three = new JButton("3");
three.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc2.weightx = 0.5;
cc2.insets = new Insets(4,0,0,3);
cc2.gridx = 5;
cc2.gridy = 4;
center.add(three, cc2);
four = new JButton("4");
four.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc2.weightx = 0.5;
cc2.insets = new Insets(4,0,0,3);
cc2.gridx = 6;
cc2.gridy = 4;
center.add(four, cc2);
five = new JButton("5");
five.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc2.weightx = 0.5;
cc2.insets = new Insets(4,0,0,3);
cc2.gridx = 2;
cc2.gridy = 5;
center.add(five, cc2);
six = new JButton("6");
six.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc2.weightx = 0.5;
cc2.insets = new Insets(4,0,0,3);
cc2.gridx = 3;
cc2.gridy = 5;
center.add(six, cc2);
seven = new JButton("7");
seven.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc2.weightx = 0.5;
cc2.insets = new Insets(4,0,0,3);
cc2.gridx = 4;
cc2.gridy = 5;
center.add(seven, cc2);
eight = new JButton("8");
eight.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc2.weightx = 0.5;
cc2.insets = new Insets(4,0,0,3);
cc2.gridx = 5;
cc2.gridy = 5;
center.add(eight, cc2);
nine = new JButton("9");
nine.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc2.weightx = 0.5;
cc2.insets = new Insets(4,0,0,3);
cc2.gridx = 6;
cc2.gridy = 5;
center.add(nine, cc2);
space = new JButton(" ");
space.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 20));
cc2.weightx = 0.5;
cc2.insets = new Insets(4,0,0,0);
cc2.gridwidth = 5;
cc2.gridheight = 1;
cc2.ipadx = 222;
cc2.ipady = 20;
cc2.gridx = 1;
cc2.gridy = 6;
center.add(space, cc2);
zero.addMouseListener(this);one.addMouseListener(t his);two.addMouseListener(this);
three.addMouseListener(this);four.addMouseListener (this);five.addMouseListener(this);
six.addMouseListener(this);seven.addMouseListener( this);eight.addMouseListener(this);
nine.addMouseListener(this);capsLock.addMouseListe ner(this);
a.addMouseListener(this);b.addMouseListener(this); c.addMouseListener(this);d.addMouseListener(this);
e.addMouseListener(this);f.addMouseListener(this); g.addMouseListener(this);h.addMouseListener(this);
i.addMouseListener(this);j.addMouseListener(this); k.addMouseListener(this);l.addMouseListener(this);
m.addMouseListener(this);n.addMouseListener(this); o.addMouseListener(this);p.addMouseListener(this);
q.addMouseListener(this);r.addMouseListener(this); s.addMouseListener(this);t.addMouseListener(this);
u.addMouseListener(this);v.addMouseListener(this); w.addMouseListener(this);x.addMouseListener(this);
bspace.addMouseListener(this);space.addMouseListen er(this);z.addMouseListener(this);y.addMouseListen er(this);
}
public void mouseClicked(MouseEvent e)
{
if (e.getSource() == capsLock)
{
capsPressed = true;
}
else if (e.getSource() == a)
{
if (capsPressed){
myTextField.setText( myTextField.getText() + "A");
capsPressed = false;
}else if(capsPressed == false)
{
myTextField.setText( myTextField.getText() + "a");
capsPressed = false;
}
}
}
public void mouseEntered(MouseEvent e)
{
// if (e.getSource() == a){ System.out.println("Test1");}
}
public void mouseExited(MouseEvent e)
{
//if (e.getSource() == a){ System.out.println("Test1");}
}
public void mousePressed(MouseEvent e)
{
//if (e.getSource() == a){ System.out.println("Test1");}
}
public void mouseReleased(MouseEvent e)
{
//i/f (e.getSource() == a){ System.out.println("Test1");}
}
/* public static void main(String [] args)
{
JFrame f = new JFrame();
f.add(new CharacterPadSpace(new JTextField()));
f.setLocation(50, 50);
f.setSize(470, 500);
f.setVisible(true);
}*/
}
I am trying to run the first clsss ... Thanks
The CharacterPadSpace works silky smooth and when compiling everything seems ok
That is not an SSCCE. And when posting code, please use the code tags- unformatted code is really hard to read.
Why class is your main method in? What class are you trying to run? Boil your problem down to an SSCCE, and we'll go from there.
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
The CharacterPadSpace works silky smooth and when compiling everything seems ok
What is SSCCE cause I am trying to click on what you sent me that hyperlink marked in blue and nothing is loaded
Sorry, their site must be down. But an SSCCE is a short, self-contained, compilable example. Basically, you should narrow your problem down to as few lines as possible while still showing your error- in your case, a basic Hello World would do, without a gui, which shows the relationship between your classes, where your main method is, etc. Please don't forget the code tags.
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
I am trying to run the Testing class ... but there is nothing when it comes to compiling its a run time error and the problem I think is the Testing class because the other works smooth
Like I said- what class is your main method in? What class are you trying to run? Exactly how are you trying to run it?
An SSCCE would help answer all of these questions.
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!