Error NoSuchMethod

Please help me!!! I am new in java and I tried the next programm:

import javax.swing.JOptionPane;

class My_programm {

int a;

int b;

int S;

public static void main( String args[]) {

{

a = Integer.parseInt(JOptionPane.showInputDialog("First num"));

b = Integer.parseInt(JOptionPane.showInputDialog("Second num"));

S=a+b;

System.out.println("The Sum");

System.out.println(S);

;

}

}

}

When I run it, I get the error Exception in thread "main" java.lang.NoSuchMethodError: main

Please help me

[602 byte] By [Java_New_Newcomera] at [2007-11-27 10:03:25]
# 1

The code you posted does not compile so it appears that the code you posted is not what you are running. For one thing, you have "My_programm" where you probably want "My_program"

When you post code, use the code tags - there's a button labeled code right next to the Spell Check button. Also, always post the full, exact error message.

atmguya at 2007-7-13 0:38:23 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2

Sorry! I am a newcomer!

At compilation I get the error : non-static variable __(an letter a,b,S) cannot be referenced from a static context.

import javax.swing.JOptionPane;

public class Programul_meu {

private int a;

private int b;

private int S;

public static void main( String args[]) {

{

a = Integer.parseInt(JOptionPane.showInputDialog("Primul termen al sumei"));

b = Integer.parseInt(JOptionPane.showInputDialog("Al doilea termen al sumei"));

S=a+b;

System.out.println("Suma este");

System.out.println(S);

}

}

}

IF YOU CAN HELP ME AND I AM OFFLINE, MY EMAIL ADDRES IS

bidaeusebiu@yahoo.com

Java_New_Newcomera at 2007-7-13 0:38:23 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 3

import javax.swing.JOptionPane;

public class Programul_meu {

private int a;

private int b;

private int S;

public void main( String args[]) {

{

;

a = Integer.parseInt(JOptionPane.showInputDialog("Primul termen al sumei"));

b = Integer.parseInt(JOptionPane.showInputDialog("Al doilea termen al sumei"));

S=a+b;

System.out.println("Suma este");

System.out.println(S);

}

}

}

This program works to compile, but when I run it I get the error Exception in thread "main" java.lang.NoSuchMethodError: main

Java_New_Newcomera at 2007-7-13 0:38:23 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 4

Look closely when you post a message. Right above the text area is a button labeled "code" Click on that button. Then paste your code between the code tags [code] and [/code]

In the code you posted, S is an instance variable. So are a & b. Instance variable means they belong to an instance of the class. You have not created an instance. You create an instance with the "new' operator.

With what I think you are trying to do, the easiest fix is to make a, b, and S part of the main method.

atmguya at 2007-7-13 0:38:23 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 5

> This program works to compile, but when I run it I

> get the error Exception in thread "main"

> java.lang.NoSuchMethodError: main

When you launch a Java application, the JVM looks for a method inside the class you specified with a format ofpublic static void main(String[] args)

Because you did not have "static" in your main method, the JVM can not find it - therefore NoSuchMethodError:main

atmguya at 2007-7-13 0:38:23 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 6

Thanks! I found the error and now the program works.

Now I have a question: Can I compile the *.class file in another type of file (better exe) or jar because I want to run the program by double click on a computer which havent Java Software(JDK) ?

IF I CAN , tell me more informations about how to do it!

The correct code:

import javax.swing.JOptionPane;

public class Programul_meu {

static int a;

static int b;

static int S;

public static void main( String args[]) {

{

;

a = Integer.parseInt(JOptionPane.showInputDialog("Primul termen al sumei"));

b = Integer.parseInt(JOptionPane.showInputDialog("Al doilea termen al sumei"));

S=a+b;

System.out.println("Suma este");

System.out.println(S);

}

}

}

Java_New_Newcomera at 2007-7-13 0:38:23 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...