i'm making a simple program that will accept 7 input using JOptionPane
i'm found out that JOptionPane has been used 7 times i want to transform in function i make it but i encounter an error.

import javax.swing.JOptionPane;

public class SevenWord2A{

public static void main() throws NoSuchMethodError 
{
String word1="";
String word2="";
String word3="";
String word4="";
String word5="";
String word6="";
String word7="";

getWord();

String msg = word1 + " " + word2 + " " + word3 + " " + word4 + " " + word5 + " " + word6 + " " + word7;
JOptionPane.showMessageDialog(null, msg);
}

String Function getWord(){

  JOptionPane.showInputDialog("Enter Word");
  
}
}

and this is the error


java.lang.NoSuchMethodError: main
Exception in thread "main"

Recommended Answers

All 2 Replies

First of all don't put a 'throws' at the main.
Second of all the error is very easy to figure out. Check your notes on how to write and run a simple program.

First of all don't put a 'throws' at the main.
Second of all the error is very easy to figure out. Check your notes on how to write and run a simple program.

agree with javaAddict:
just another remark:
either make the getWord() method static, or call it from an instance of SevenWords2a

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.