Java.lang.NoSuchMethodError: main, only when I run project, not file

When I am running my project to test it I am getting the following error message.
Exception in thread "main" java.lang.NoSuchMethodError: main
I have checked all the files are in the corrcet place, and all called what the class is called, which they are, I do not know where else to look. And I have to hjand this in is a week and a half!!!
Also, the error only happens when I run the PROJECT and not when I run the file on its own. Below is the code. Does anyone have any ideas to help me?
public class ToolList
     private Tool[] toolArray;
     public ToolList()
          toolArray = new Tool[100];
          for (int i=0;i<toolArray.length;i++)
               toolArray=null;
     }//end toolList default constructor
     public boolean addTool (Tool toolIn)
          for (int i=0;i<toolArray.length;i++)
               if (toolArray[i]==null)
                    toolArray[i]=toolIn;
                    return true;
          return false;
     public static void main(String args[])
               Tool Hammer = new Tool("Hammer","H0001",16.45F);
               ToolList tl1 = new ToolList();
               if (tl1.addTool(Hammer) ) System.out.println("Tool added");
Thanks
Java Chick :)

Thanks all!
"Java has no concept of a 'project' so I assume that you are using an IDE for development. Most IDEs have a 'project' concept and some means of defining the 'main' class for the 'project'. Which IDE are you using?
I am using JCreator V3 LE. I have many files set up, Tool.java, ToolList.java, Company.java, Customer.java and CustomerList.java.
At the moment I am just tesing each class as I go and adding Main to the bottom of the classs I am testing.
but, as this one has an array that refers to other objects I thought I had to create this in a seperate file and run the group of files together.
"James 91 - Environment Variables"
When I check the class path I see the following:
C:\Program Files\Xinox Software\JCreatorV3 LE\MyProjects\Main Project\classes;C:\Program Files\Java\jdk1.5.0\jre\lib\rt.jar;C:\Program Files\Java\jdk1.5.0\lib\dt.jar;C:\Program Files\Java\jdk1.5.0\lib\tools.jar;C:\Program Files\Java\jdk1.5.0\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.5.0\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.5.0\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.5.0\jre\lib\ext\sunpkcs11.jar
Should I change this to C\Program Files\Java\jdk1.5.0\lib\tools.jar
Thanks
Java Chick.

Similar Messages

  • Exception in thread "main" java.lang.NoSuchMethodError: main -- Help

    I am new to Java programming and I have been working out of a book trying to learn the language. I am working on a Ubuntu system using Eclipse. I get an error when I try to run this app. It is: Exception in thread "main" java.lang.NoSuchMethodError: main. I have Googled it and read different possible solutions, but none have helped. Can someone help me solve this?
    Here is the code for battleshipGameTestDrive.java:_
    import java.util.ArrayList;
    public class battleshipGameTestDrive
         public static void main(String[] args, ArrayList<String> locations)      
              int numOfGuesses = 0;
              boolean isAlive = true;
              GameHelper helper = new GameHelper();
              battleshipGame ship = new battleshipGame();
              for (int ctr = 1; ctr < 4; ctr++)
                   int randomNum = (int) (Math.random() * 5);          
                   locations.add(Integer.toString(randomNum));
                   ship.setLocationCells(locations);
              while (isAlive == true){
                   String userGuess = helper.getUserInput("Enter a number (1-7): ");
                   numOfGuesses++;
                   String result = ship.checkYourself(userGuess);
                   if (result.equals("kill")){
                        isAlive = false;
                        System.out.println("You took " + numOfGuesses + " guesses");
                   } // close result if
              }  //end while loop
         }// end of main
    }// end of battleshipGameTestDrive class
    Here is the code for the battleshipGame class.java:_
    import java.util.ArrayList;
    public class battleshipGame {
         private ArrayList<String> locationCells;
         public void setLocationCells(ArrayList<String> loc){
              locationCells = loc;
         public String checkYourself(String userInput){
              String result = "miss";          
              int index = locationCells.indexOf(userInput);
              if (index >= 0){
                   locationCells.remove(index);
                   if (locationCells.isEmpty()){
                        result = "kill";
                   }else{
                        result = "hit";
                   }// close if
              }// closer outer if
              return result;
         }     //close method
    }     //close class

    Hello,
    I saw your short message youe sent to someone who had a problem : Exception in thread "main" java.lang.NoSuchMethodError :main
    So I was thinking maybe you could help me I struggle with this code fro 3weeks, this is a code I save it later as
    import java.awt.*;
    import java.awt.event.*;
    class Party {
    public void makeInvitation(){
    Frame f = new Frame();
    Label l = new Label("Party at Tom's");
    Button b = new Button("Sure");
    Button c = new Button("Noo...");
    Panel p = new Panel();
    p.add(l);
    I write this code in Notepad++ than I save it as java file with looks like this : Java source file (*.java)
    - than in Command Prompt I write : javac Party.java as usual and it comes with this error below Exception in thread "main" .......
    I have no idea what's wrong with it.Can you help me
    Thank you in advance

  • Java.lang.NoSuchMethodError: sqlj.tools.Sqlj: method resetStaticVariables()V not foun

    I would like to retrieve data from Oracle8.0.5 using sqlj.
    i tried:
    <%@page language="sqlj
    import= sqlj.runtime.ref.DefaultContext,oracle.sqlj.runtime.Oracle"%>
    and i've got the error:
    java.lang.NoSuchMethodError: sqlj.tools.Sqlj: "method resetStaticVariables()V not found"
    someone helps?
    thanx

    This uses a feature which is only found in post 8.1.6.1 versions of Oracle SQLJ. You have two choices:
    (1) Download ojsp 1.0.0.6.1 or later from OTN. This contains an updated SQLJ version.
    (2) Or wait for the SQLJ 8.1.7 release (or later) in the next couple of weeks.
    null

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

    I know you answered this questions a thousand times, but from all the threads i've read, i understand that it is also a program specific problem. I'm an absolute beginner in Java coding, learning it right now at university... I also undertood from other threads u want me to post in the correct way with the code attached to the message. i hope the form i am posting this thread in is ok... sorry to bother you, but it would be really nice if we could solve this problem somehow:
    I created a java file, which compiled without problems; but when i try to run the program, my terminal gives out the failure message stated above.
    I already set the classpath variable to the directory i am working in, so i don't think that this is the problem...
    anyway, here's the code, hope you can deal with it.
    class Widerstand{
              //Attribute
         float rho;
         float laenge;
         float flaeche;
         public float r;
              //Widerstand aus der Formel
              Widerstand(float rho, float laenge, float flaeche){
                   float r=rho*(laenge/flaeche);
              } //Formel
              //Widerstandswert (direkt �bergeben)
              Widerstand(float r){
                   r=r;
              } //Wert     
                   //Wert zur�ckgeben
                   float sWert(){
                        return r;
    }//class
    class Netzwerk{
    public static void main(String[] args) {
         float rho=Terminal.askFloat("Rho=");
         float laenge=Terminal.askFloat("Leiterlaenge=");
         float flaeche=Terminal.askFloat("Leiterdurchmesser=");
         }//Argumente
    }//class

    The error is telling you that the error is:
    Thrown if an application tries to call a specified method of a class (either static or instance), and that class no longer has a definition of that method.
    Normally, this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed.
    Delete the .class files and recompile programs to insure that the .class files are valid.

  • Error watching JMS queues with JMSUtils: java.lang.NoSuchMethodError: main

    Hi. I'm trying to use the command line utility JMSUtils to see if I have configured correctly a new queue in oc4j server but when I try to use execute it following the instructions I have found on the net it doesn't appear to be in the oc4j.jar
    I found that class in oc4jclient.jar but without a main method.
    I use the 10g Release 3 (10.1.3.0.0) for Microsoft Windows
    The instruction I execute is:
    C:\product\10.1.3\OracleAS_1\j2ee\home>java -classpath c:\ora10g\j2ee\home\oc4j.
    jar;c:\ora10g\j2ee\home\lib\jms.jar com.evermind.server.jms.JMSUtils -username admin -password welcome destinations
    Exception in thread "main" java.lang.NoClassDefFoundError: com/evermind/server/j
    ms/JMSUtils
    Mensaje editado por:
    user515269
    Mensaje editado por:
    user515269

    When I try to execute the JMSUtils class that's inside
    oc4j-internal.jar appears the same exception I had
    executing the class that's inside oc4jclient.jar:
    NoSuchMethodError: main
    Anybody knows why this class doesn't have a main method
    or how can I execute it?Jose:
    It seems that the command line utility JMSUtils is removed from oc4j 10.1.3, although the class is still packaged into some oc4j jar. According to the documentation, "In this release, OracleAS JMS Utility functionality is available as attributes and operations on various MBeans, replacing the deprecated command line interface of previous releases.".
    Please see the section "OracleAS JMS Utility" of the book "Oracle® Containers for J2EE
    Services Guide, 10g Release 3 (10.1.3) for Windows or UNIX, B14427-01", which is available on line.
    Hope this helps.

  • Getting java.lang.Null pointer Exception when i close the pdf file.

    Hi,
    my application is java based thick client application.
    From my application, i am generating report file using crystal report tool.
    the report file is exported as pdf format and stored in my local macine. from this path, am displaying the report in a SWT browser.
    till now its working fine. when i close the browser, i am getting java.lang.null.pointer exception.
    i dont understand from this exception, printed in console.
    please help me.
    java.lang.NullPointerException
    at org.eclipse.swt.ole.win32.OleClientSite.onPaint(OleClientSite.java:921)
    at org.eclipse.swt.ole.win32.OleClientSite.access$2(OleClientSite.java:906)
    at org.eclipse.swt.ole.win32.OleClientSite$1.handleEvent(OleClientSite.java:131)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1027)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1012)
    at org.eclipse.swt.widgets.Composite.WM_PAINT(Composite.java:1424)
    at org.eclipse.swt.widgets.Control.windowProc(Control.java:3842)
    at org.eclipse.swt.widgets.Display.windowProc(Display.java:4541)
    at org.eclipse.swt.internal.ole.win32.COM.CoFreeUnusedLibraries(Native Method)
    at org.eclipse.swt.ole.win32.OleClientSite.releaseObjectInterfaces(OleClientSite.java:1084)
    at org.eclipse.swt.ole.win32.OleControlSite.releaseObjectInterfaces(OleControlSite.java:683)
    at org.eclipse.swt.ole.win32.OleClientSite.onDispose(OleClientSite.java:852)
    at org.eclipse.swt.ole.win32.OleClientSite.access$1(OleClientSite.java:847)
    at org.eclipse.swt.ole.win32.OleClientSite$1.handleEvent(OleClientSite.java:128)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1027)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1008)
    at org.eclipse.swt.widgets.Widget.release(Widget.java:804)
    at org.eclipse.swt.widgets.Composite.releaseChildren(Composite.java:755)
    at org.eclipse.swt.widgets.Widget.release(Widget.java:807)
    at org.eclipse.swt.widgets.Composite.releaseChildren(Composite.java:755)
    at org.eclipse.swt.widgets.Widget.release(Widget.java:807)
    at org.eclipse.swt.widgets.Widget.dispose(Widget.java:441)
    at com.siemens.med.cad.hqm.reports.ReportViewer$1.widgetDisposed(ReportViewer.java:273)
    at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:117)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1027)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1008)
    at org.eclipse.swt.widgets.Widget.release(Widget.java:804)
    at org.eclipse.swt.widgets.Widget.dispose(Widget.java:441)
    at org.eclipse.swt.widgets.Decorations.dispose(Decorations.java:446)
    at org.eclipse.swt.widgets.Shell.dispose(Shell.java:674)
    at org.eclipse.swt.widgets.Decorations.closeWidget(Decorations.java:308)
    at org.eclipse.swt.widgets.Decorations.WM_CLOSE(Decorations.java:1643)
    at org.eclipse.swt.widgets.Control.windowProc(Control.java:3789)
    at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:337)
    at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1576)
    at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:1937)
    at org.eclipse.swt.widgets.Display.windowProc(Display.java:4528)
    at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method)
    at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2366)
    at org.eclipse.swt.widgets.Shell.callWindowProc(Shell.java:477)
    at org.eclipse.swt.widgets.Control.windowProc(Control.java:3877)
    at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:337)
    at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1576)
    at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:1937)
    at org.eclipse.swt.widgets.Display.windowProc(Display.java:4528)
    at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method)
    at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2366)
    at org.eclipse.swt.widgets.Shell.callWindowProc(Shell.java:477)
    at org.eclipse.swt.widgets.Control.windowProc(Control.java:3877)
    at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:337)
    at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1576)
    at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:1937)
    at org.eclipse.swt.widgets.Display.windowProc(Display.java:4528)
    at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
    at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2371)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3420)
    at com.siemens.med.cad.hqm.view.mainUI.HQMMainForm.buildMainShell(HQMMainForm.java:246)
    at com.siemens.med.cad.hqm.event.UserLoginEventHandler.loginDisplay(UserLoginEventHandler.java:240)
    at com.siemens.med.cad.hqm.event.UserLoginEventHandler.widgetSelected(UserLoginEventHandler.java:97)
    at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:228)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3823)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3422)
    this is the code i have written for display the report file in a browser:
    Display display = Display.getDefault() ;
         Shell shell = new Shell(display, SWT.RESIZE | SWT.CLOSE | SWT.MIN | SWT.MAX | SWT.APPLICATION_MODAL);
    shell.setText(reportTitle);
    shell.setLayout(new FillLayout());
    shell.setMaximized(false);
    shell.setSize(800, 600);
    Composite comp = new Composite(shell, SWT.NONE);
    comp.setLayout(new FillLayout());
    final Browser browser = new Browser(comp, SWT.FLAT);
    try {
    File file = new File(exportFile);
    URL url = file.toURL();
    browser.setUrl("file:" + url.getPath());
    } catch (MalformedURLException malURLEx) {
    // malURLEx.printStackTrace();
    throw new ProgrammingExceptionAdapter(malURLEx);
    shell.addDisposeListener(new DisposeListener() {
    public void widgetDisposed(DisposeEvent arg0) {
    File file = new File(exportFile);
    if (file != null && file.exists()) {
    file.delete();
    browser.dispose();
    shell.open();
    shell.setFocus()'

    TitiTruc, welcome to the forum. Please don't post in threads that are long dead. When you have a question, start your own topic. Feel free to provide a link to an old post that may be relevant to your problem.
    I'm locking this thread now.
    db

  • Exception in thread "main" java.lang.NoSuchMethodError: main (Error)

    Hello,
    I'm new to learning Java and I'm receiving the following error message whenever I try to run the following program. Can someone help?
    //code
    class Books {
         String title;
         String author;
         class BooksTestDrive {
         public static void main(String [] args)     {
         Books [] myBooks = new Books[3];
         int x = 0;
         myBooks[0] = new Books();
         myBooks[1] = new Books();
         myBooks[2] = new Books();
         myBooks[0].title = "The Grapes of Java";
         myBooks[1].title = "The Java Gatsby";
         myBooks[2].title = "The Java Cookbook";
         myBooks[0].author = "bob";
         myBooks[1].author = "sue";
         myBooks[2].author = "ian";
         while (x < 3) {
         System.out.print(myBooks[x].title);
         System.out.print(" by ");
         System.out.println(myBooks[x].author);
         x = x + 1;
    //end of code
    Thanks,
    H

    1.) Use the code button when posting your code, it makes it more readable.
    2.) You should have posted the error message in the text as well, it's slightly confusing this way.
    NoSuchMethodError means that Java wanted to invoke a method that's not there. In this case it's called "main". So you tried to run a Java class that does not have a main method. How did you try to run your Program (exact command, please)?

  • Java.lang.NoSuchMethodError: main

    I am still trying to read a csv file, but getting an error, see subject.
    I think I nust go on a course as I just can't believe that it's thar hard just to read a simple csv file in java.
    Can anybody recommend a good course that will explain all.
    This is my source code, personaly I think it's in a mess....
    package CsvReader;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    public class CsvReader {
         public CsvReader(FileReader fileReader) {
              // TODO Auto-generated constructor stub
         public static void main(String[] args,
              CsvReader CsvReaderthrows) throws FileNotFoundException
              CsvReader reader = new CsvReader(new FileReader("cash 20 feb 2009.csv"));
         String [] nextLine;
         while ((nextLine = reader.readNext()) != null) {
         // nextLine[] is an array of values from the line
         System.out.println(nextLine[0] + nextLine[1] );
         private String[] readNext() {
              // TODO Auto-generated method stub
              return null;
    Help will bbe appreciated.
    Joo

    this should keep you busy for a while.
    package forums;
    import java.util.Date;
    import java.util.Arrays;
    import java.util.List;
    import java.util.ArrayList;
    import java.io.Closeable;
    import java.io.File;
    import java.io.FileReader;
    import java.io.BufferedReader;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    class ParseException extends RuntimeException {
      private static final long serialVersionUID = 1L;
      ParseException(String message, Throwable cause) { super(message, cause); }
    class CashReceipt
      private int receiptNumber;
      private Date dateReceived;
      private String whoFrom;
      private String whatFor;
      private double amount;
      public CashReceipt(int receiptNumber, Date dateReceived, String whoFrom, String whatFor, double amount) {
        this.receiptNumber = receiptNumber;
        this.dateReceived = dateReceived;
        this.whoFrom = whoFrom;
        this.whatFor = whatFor;
        this.amount = amount;
      public int getReceiptNumber() { return this.receiptNumber; }
      public void setReceiptNumber(int receiptNumber) { this.receiptNumber = receiptNumber; }
      public Date getDateReceived() { return this.dateReceived; }
      public void setDateReceived(Date dateReceived) { this.dateReceived = dateReceived; }
      public String getWhoFrom() { return this.whoFrom; }
      public void setWhoFrom(String from) { this.whoFrom = whoFrom; }
      public String getWhatFor() { return this.whatFor; }
      public void setWhatFor(String whatFor) { this.whatFor = whatFor; }
      public double getAmount() { return this.amount; }
      public void setAmount(double amount) { this.amount = amount; }
      @Override
      public String toString() {
        return "CashReceipt: "
          +" receiptNumber=\""+getReceiptNumber()+"\""
          +" dateReceived=\""+getDateReceived()+"\""
          +" whoFrom=\""+getWhoFrom()+"\""
          +" whatFor=\""+getWhatFor()+"\""
          +" amount=\""+getAmount()+"\""
    interface LineParser<E> {
      E parse(String line) throws ParseException;
    class CashReceiptCsvLineParser implements LineParser<CashReceipt>
      public static String fieldSeperator = "\\s*,\\s*";
      public static String dateFormat = "yyyy-MM-dd";
      private DateFormat dateParser = null;
      public CashReceiptCsvLineParser() {
        dateParser = new SimpleDateFormat(dateFormat);
      public CashReceipt parse(String line) throws ParseException {
        String[] fields = line.split(fieldSeperator);
        try {
          return new CashReceipt(          // We recieved some money:
              Integer.valueOf(fields[0])   // * receipt-number
            , dateParser.parse(fields[1])  // * when
            , fields[2]                    // * who from
            , fields[3]                    // * what for
            , Double.valueOf(fields[4])    // * how much
        } catch (Exception e) {
          throw new ParseException("Unparsable: "+line, e);
    interface LineReader<E> extends Closeable {
      public E read() throws IOException;
    class GenericLineReader<E> implements LineReader<E>
      private BufferedReader reader = null;
      private LineParser<E> parser = null;
      public GenericLineReader(BufferedReader reader, LineParser<E> parser) {
        this.reader = reader;
        this.parser = parser;
      public E read() throws IOException {
        String line = reader.readLine();
        if(line==null) return null;
        return parser.parse(line);
      public void close() throws IOException {
        if(reader!=null) reader.close();
        reader = null;
    }... PTO ...

  • Java.lang.NoSuchMethodError: main                  Exception in thread main

    I am a student currently trying to teach myself java with the aid of sams teach yourself java book, but whilst doing one of the examples I have become stuck.
    I get the message that I have posted as the subject title, the book is designed to use java 2 with netbeans 4.0 java 1.5 I think which I guess the code is written for,
    but at uni they have netbeans 3.6 java 1.4 so we have been advised to use this so there is no problems when working on the same projects and uni and at home,
    anyway can someone please help the code is posted below.
    thanx in advance
    import java.awt.*;
    import javax.swing.*;
    public class MessagePanel extends JPanel {
        GridBagLayout gridbag = new GridBagLayout();
        public MessagePanel() {
            super();
            GridBagConstraints constraints;
            setLayout(gridbag);
            JLabel toLabel = new JLabel("To: ");
            JTextField to = new JTextField();
            JLabel subjectLabel = new JLabel("Subject: ");
            JTextField subject = new JTextField();
            JLabel ccLabel = new JLabel("CC: ");
            JTextField cc = new JTextField();
            JLabel bccLabel = new JLabel("BCC: ");
            JTextField bcc = new JTextField();
            addComponent(toLabel, 0, 0 , 1, 1, 10, 100,
                GridBagConstraints.NONE, GridBagConstraints.EAST);
            addComponent(to, 1, 0, 9, 1, 90, 100,
                GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST);
            addComponent(subjectLabel, 0, 1, 1, 1, 10, 100,
                GridBagConstraints.NONE, GridBagConstraints.EAST);
            addComponent(subject, 1, 1, 9, 1, 90, 100,
                GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST);
         addComponent(ccLabel, 0, 2, 1, 1, 10, 100,
                GridBagConstraints.NONE, GridBagConstraints.EAST);
            addComponent(cc, 1, 2, 4, 1, 40, 100,
                GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST);
            addComponent(bccLabel, 5, 2, 1, 1, 10, 100,
                GridBagConstraints.NONE, GridBagConstraints.EAST);
            addComponent(bcc, 6, 2, 4, 1, 40, 100,
                GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST);
        private void addComponent(Component component, int gridx, int gridy,
            int gridwidth, int gridheight, int weightx, int weighty, int fill,
            int anchor) {
            GridBagConstraints constraints = new GridBagConstraints();
            constraints.gridx = gridx;
            constraints.gridy = gridy;
            constraints.gridwidth = gridwidth;
            constraints.gridheight = gridheight;
            constraints.weightx = weightx;
            constraints.weighty = weighty;
            constraints.fill = fill;
            constraints.anchor = anchor;
            gridbag.setConstraints(component, constraints);
            add(component);
    }I have copied exactly what the book says and downloaded the files from the website and everything is the same but it just won't work?

    My guess is that the main method is in another class. It would probably look something like this:
    public static void main(String[] args)
         JFrame f = new JFrame();
         f.setSize(500, 500);
         f.setLocation(20, 20);
         f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         f.setContentPane(new MessagePanel());
         f.setVisible(true);
    }

  • Regarding java.lang.NoSuchMethodError

    Hi friends
    I want to run my servlet program....i am using tomcat as server....
    i set my path as follow
    java_home=c\sun\jdk
    path =c:\sun\jdk\bin
    my sevlet program is at the folder D:\jakarta-tomcat-5.0.19\webapps\myapp\WEB-INF\classes\HelloWorld
    I set the class path as D:\jakarta-tomcat-5.0.19\common\lib\servlet-api.jar
    When i run my program i am getting the error of Exception in thread "main" java.lang.NoSuchMethodError: main
    My program is
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class HelloWorld extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head>");
    out.println("<title>Hello World!</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("<h1>Hello World!</h1>");
    out.println("</body>");
    out.println("</html>");
    Pls anybody help me to solve my problem

    Hello,
    The error is because there is no main function in the program.
    Also like "CeciNEstPasUnProgrammeur" replied servlets cannot be executed as a standalone applciation. . Try running it from the web server..
    Regards,
    Prasanna.

  • Why do I get a "java.lang.NoSuchMethodError"?

    Hello!
    I going to send a mail with a socketconnection, the program worked when I not was using GUI. Now I'm trying to make a GUI-version BUT it's not working. There is no problem to compile the program but when I am running the program I get a "java.lang.NoSuchMethodError"...why?
    I'v not been programming to much so I would really appreciate some tips!
    Some namings are in swedish! Sorry for that!
    Thank you for helping me// MM
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import javax.swing.*;
    public class Lab3 {
    Window frame;
    public void main(String args[]) throws Exception{
         frame=new Window();
         Maila mail     =new Maila(args);
         String file=mail.hittaFil(args);
         mail.maila(file);
    class Window extends JFrame implements ActionListener{
         public JFrame mailFrame;
         public JPanel mailPanel;
         public JTextArea mailMedd;
         public JTextField adressField, filNamnField, mailAdressField, meddelandeField;
         public JLabel webbAdressLabel, filNamnLabel, mailAdressLabel, meddelandeLabel, blankLabel, svarLabel;
         public JButton searchButton, sendButton;
    public Window() {
         mailFrame = new JFrame("Finn och skicka fil");
         mailFrame.setSize(80, 150);
         mailPanel = new JPanel();
         // Add the widgets.
         addWidgets();
         // Add the panel to the frame.
         // Exit when the window is closed.
    mailFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         // Show the frame
         mailFrame.pack();
         mailFrame.setVisible(true);
    // Create and add the widgets for frame
    private void addWidgets() {
         // Create widgets.
         mailMedd = new JTextArea(6,3);
         adressField = new JTextField(30);
         filNamnField = new JTextField(30);
         mailAdressField = new JTextField(30);
         meddelandeField = new JTextField(30);
         webbAdressLabel = new JLabel("Webb-Adress: ", SwingConstants.RIGHT);
         filNamnLabel = new JLabel(" Filnamn: ", SwingConstants.RIGHT);
         blankLabel = new JLabel("", SwingConstants.RIGHT);
         meddelandeLabel = new JLabel(" Meddelande:", SwingConstants.RIGHT);
         svarLabel = new JLabel(" ");
         mailAdressLabel = new JLabel(" Skicka till: ", SwingConstants.RIGHT);
         searchButton = new JButton("Search for file");
         sendButton = new JButton("Send mail");
         // Listen to events from buttons.
         searchButton.addActionListener(this);
         sendButton.addActionListener(this);
         // Add widgets to container.
         Box b1h1 = Box.createHorizontalBox();
         Box b1h2 = Box.createHorizontalBox();
         Box b1h3 = Box.createHorizontalBox();
         Box b1h4 = Box.createHorizontalBox();
         Box b1h5 = Box.createHorizontalBox();
         Box b1h6 = Box.createHorizontalBox();
         Box b1h7 = Box.createHorizontalBox();
         Box bv = Box.createVerticalBox();
         b1h1.add(webbAdressLabel);
         b1h1.add(adressField);
         b1h2.add(filNamnLabel);
         b1h2.add(filNamnField);
         b1h3.add(blankLabel);
         b1h3.add(searchButton);
         b1h6.add(mailAdressLabel);
         b1h6.add(mailAdressField);
         b1h7.add(blankLabel);
         b1h7.add(sendButton);
         b1h4.add(meddelandeLabel);
         b1h4.add(blankLabel);
         b1h5.add(blankLabel);
         b1h5.add(svarLabel);
         bv.add(Box.createVerticalStrut(15));     
         bv.add(b1h1);
         bv.add(Box.createVerticalStrut(3));
         bv.add(b1h2);
         bv.add(Box.createVerticalStrut(15));
         bv.add(b1h3);
         bv.add(Box.createVerticalStrut(25));
         bv.add(b1h4);
         bv.add(Box.createVerticalStrut(15));
         bv.add(mailMedd);
         bv.add(Box.createVerticalStrut(3));
         bv.add(b1h5);
         bv.add(Box.createVerticalStrut(30));
         bv.add(b1h6);
         bv.add(Box.createVerticalStrut(15));
         bv.add(b1h7);
         bv.add(Box.createVerticalStrut(3));
         mailFrame.getContentPane().add(bv, BorderLayout.CENTER);
    // Implementation of ActionListener interface.
    public void actionPerformed(ActionEvent event) {
    class Maila{
    String[] args;
    public Maila(String[] args){
         this.args=args;
         public void maila(String file) throws IOException{
         Socket mailSocket;
         int j=0;
         String from,till,kopia,avsandare,mottagare;
         Vector to = new Vector();
         String subject;
         String data;
         BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
         PrintWriter out;
         BufferedReader mailIn;
         System.out.print("Fr?n: ");
         from=in.readLine();
         System.out.print("Till: ");
         till = in.readLine();
         //System.out.print("Skickakopia till: ");
         //kopia=in.readLine();
         //System.out.print("Avs?ndare: ");
         //avsandare=in.readLine();
         //System.out.print("Mottagare:: ");
         //mottagare=in.readLine();
         StringTokenizer st = new StringTokenizer(till);
         int nr = st.countTokens();
         while(st.hasMoreTokens()){
         nr = st.countTokens();
         to.add(st.nextToken());
         nr = st.countTokens();
         System.out.print("?mne: ");
         subject = in.readLine();
         System.out.println();
         System.out.println("Skriv ditt meddelande. Avsluta med 'Enter'");
         data = in.readLine();
         for(int k=0; k<to.size(); k++){
         String tillfadress = (String)to.elementAt(k);
         Object localhost = InetAddress.getLocalHost();
         mailSocket=new Socket("localhost",25);
         out=new PrintWriter(mailSocket.getOutputStream(), true);     
         mailIn=new BufferedReader(new InputStreamReader(mailSocket.getInputStream()));
         out.println("HELO "+"localhost");
         out.println("MAIL FROM: " + from);
         out.println("RCPT TO: " + tillfadress);
         out.println("DATA");
    out.println("Subject:" + subject);
         out.println("From: " + from);
         out.println("To: " + tillfadress);
         out.println("CC: " + tillfadress);
         out.println(data+file);
         out.println(".");
    //     System.out.println(mailIn.readLine() + "8");
         //out.flush();
         //printer.println("Subject: " + subject);
         //printer.println("From: " + sender);
         //printer.println("To: " + recipient);
         //printer.println("CC: " + cc);
         //printer.println(data);
    public String hittaFil(String[] args){
         int i;
         InputStream in = null;
         OutputStream out = null;
         String text=null;
         try{
         URL url = new URL("http://"+args[0]);
         for(i=2;i<args.length;i++){
              try{
              URL urlx = new URL(url,"~"+args);
              in = urlx.openStream();
              BufferedReader indata = new BufferedReader(new InputStreamReader(in));
              text = indata.readLine();
              catch(FileNotFoundException e){
              System.out.println("Ingen fil med givet namn hittad!");
         catch(Exception e){
         System.err.println(e);
         System.err.println("Usage: java GetURL <URL> <filename>");
         finally{
         try{
              in.close();
              out.close();
         catch(Exception e){}
         return(text);

    I don't see a main method in your code. The one declared in your Lab3.java is not static.

  • Java.lang.NoSuchMethodError weird occurence

    Hi..
    I know there are hell a lot Qs on "java.lang.NoSuchMethodError"..But I checked almost every java forum and none of them answer my situation correctly..
    Initialy I had two files
    1)test.java
    public class test{
    public static void main(String a []) {
    System.out.println(";");
    2)javac.java
    public class javac{
    public static void main(String a []) {
    System.out.println(";");
    I compiled both the files.Both were working fine. After some time I recompiled test.java.This time it gives
    "Exception in thread "main" java.lang.NoSuchMethodError: main"..The same file on recompilation...
    But the other file javac stil working fine(I din dare to recompile it since now whatever file I compile has this problem)...
    Im sure this is not a classpath problem or else we might getting NoClassDeffound error. Also there is nothing wrong in the main method declaration.
    Anybody can explain this behaviour?

    paulcw thanks for your replies...
    But I think you misunderstood my issue...
    OKI ..I still have the problem so let me explain it properly..
    Now I have the file test.java with the following content which I already compiled and can execute also...
    import java.io.*;
    public class test{
    public static void main(String a[]){
    String record = "0001 - LE1 - 850 - bytes - JPEG - JAL - 128X96 - 128x96_1k_jpg.jpg";
    String [] spiltvalues = record.split(" - ");
    for( String i: spiltvalues )
    System.out.println( i );
    On execution:
    D:\Data>java test
    0001
    LE1
    850
    bytes
    JPEG
    JAL
    128X96
    128x96_1k_jpg.jpg
    Now I move the source to some other directory(the same file) Im not changing anything.It compiles fine.When I execute I get
    D:\>java test
    Exception in thread "main" java.lang.NoSuchMethodError: main
    Now I copy the test.class of previously complied,sucessfully executed class file to D: and replace the class file which cannot be executed.
    D:\>java test
    0001
    LE1
    850
    bytes
    JPEG
    JAL
    128X96
    128x96_1k_jpg.jpg
    So this cannot be a path issue also. Both cases I haven changed the source even if I have changed please see the source I have posted..I don find any mistakes in the code.
    Im nt sure if something wrong with my javac/java exes...Before I reinstal I want to find the problem..
    Your reply is appreciated..Thanks..

  • Java.lang.NoSuchMethodError: getEncodedURL when running junits for webservi

    Hi,
    We are getting NosuchMethodError when we are trying to run the junits for the webservice clients through ant script.But when we are executing the same junits through weblogic workshop, junits are running finely.Please let me know, if any one knows the solution
    Exception:
    Caused an ERROR
    getEncodedURL
    java.lang.NoSuchMethodError: getEncodedURL
    at weblogic.wsee.util.is.InputSourceUtil.loadURL(InputSourceUtil.java:44)
    at weblogic.wsee.util.dom.DOMParser.getWebLogicDocumentImpl(DOMParser.java:118)
    at weblogic.wsee.util.dom.DOMParser.getDocument(DOMParser.java:65)
    at weblogic.wsee.wsdl.WsdlReader.getDocument(WsdlReader.java:311)
    at weblogic.wsee.wsdl.WsdlReader.getDocument(WsdlReader.java:305)
    at weblogic.wsee.jaxws.framework.jaxrpc.client.ClientEnvironmentFactory.getWsdlDef(ClientEnvironmentFactory.java:156)
    at weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory.getService(EnvironmentFactory.java:393)
    at weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory.buildDeploymentContext(EnvironmentFactory.java:581)
    at weblogic.wsee.jaxws.framework.jaxrpc.EnvironmentFactory.getDeploymentContext(EnvironmentFactory.java:570)
    at weblogic.wsee.jaxws.framework.jaxrpc.TubelineDeploymentListener.createClient(TubelineDeploymentListener.java:48)
    at weblogic.wsee.jaxws.WLSTubelineAssemblerFactory$TubelineAssemblerImpl.createClient(WLSTubelineAssemblerFactory.java:46)
    at com.sun.xml.ws.client.WSServiceDelegate.createPipeline(WSServiceDelegate.java:446)
    at com.sun.xml.ws.client.WSServiceDelegate.createEndpointIFBaseProxy(WSServiceDelegate.java:639)
    at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:342)
    at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:324)
    at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:306)
    at javax.xml.ws.Service.getPort(Service.java:92)

    Hi,
    This is the problem with the jaxws-rt.jar in my classpath.I have removed the jar from the class path then it started working
    culprit here is ‘com.sun.xml.ws.util. JAXWSUtils’ which is defined in jaxws.rt.<version>.jar. Weblogic 10 uses glassfish.jaxws.rt_2.1.3.jar.
    Could you please check in (ANT) classpath where in any other jaxws.rt.jar being referred which may not have ‘getEncodedURL’ method definition

  • Java.lang.NoSuchMethodError: init when running in a Thread

    I have a Java class that calls a C++ function (JNI) and the return of that function is a Java object:
    There�s the problematic C++ code:
    jclass taskDescriptorClass = env->FindClass("a/b/TaskDescriptor");
    if (taskDescriptorClass == NULL) {
         //Class cannot be found
         return NULL;
    jmethodID constructorMID = env->GetMethodID(taskDescriptorClass, "<init>", "void(V)");
    if (constructorMID == NULL) {
         return NULL;
    }This code as always behaved as expected, running in a JUnit test. But now I�m calling the code inside a thread (new Thread(new Runnable() { public void run() { ...NATIVE CALL...), but now I�m getting an exception:
    Exception in thread "thrd1" java.lang.NoSuchMethodError: <init>
         at a.b.JTLs.createTask(Native Method)
         at a.b.GrammarBuilder.build(GrammarBuilder.java:216)
         at a.b.GrammarManager.getModel(GrammarManager.java:230)
         at a.b.GrammarManager.getModel(GrammarManager.java:146)
         at a.b.TestGrammarManager$1.run(TestGrammarManager.java:58)
         at java.lang.Thread.run(Thread.java:595) I�m using J2SE 5 update 06
    Does anyone know why is this happening?
    Thanks

    Hi,
    This is the problem with the jaxws-rt.jar in my classpath.I have removed the jar from the class path then it started working
    culprit here is ‘com.sun.xml.ws.util. JAXWSUtils’ which is defined in jaxws.rt.<version>.jar. Weblogic 10 uses glassfish.jaxws.rt_2.1.3.jar.
    Could you please check in (ANT) classpath where in any other jaxws.rt.jar being referred which may not have ‘getEncodedURL’ method definition

  • Java.lang.NoSuchMethodError while running the Application on MI client

    Hi Experts
    During development I run my application through NWDS and worked perfect. But when I  run my application only through MI client. It through error on my programmed methods: java.lang.NoSuchMethodError:
    Any advice is highly appreciated!
    Michal

    Thanks for your reply!
    I use MI 2.5 SP20 and that trace is:
    Internal Servlet Error:
    java.lang.NoSuchMethodError: com.sap.myApp.bean.TableViewBean.setAll(Ljava/lang/String;)V
    Thanks for any advice

Maybe you are looking for

  • Problems with submit button.

    All i have run a report with the following SQL which creates the report and assignes tick box to select if you want to keep the value in the row. select HTMLDB_ITEM.CHECKBOX(1,recert,'CHECKED') "Accept",traderid,account,alias,credit,currency,allowtra

  • Why can't I download and play songs on iTunes from iCloud if I purchased Match?

    I want to play songs on my desktop from iTunes.  However, I can't click on the cloud symbol and download them onto my PC...I just get a "!" out to the left of the song.  I have no problem downloading the songs from the cloud and playing them on my iP

  • Problem with Apple products

    I tried sending this in Apple's feedback section and there wasn't enough space. This is a personal comment about Apple product, but i believe other will connect with it. i didnt know where else to put it. Firstly I am and have been an avid believer o

  • Photoshop CC selective color UNDO BUG

    do this in photoshop CC: - open an image - layer -> new adj layer -> selective color preset: custom colors: reds cyan -100% press ctrl+z for UNDO it restores the effect on the image but it doesnt update the setting to 0% same thing in all adjustment

  • Infotype Creation With a subtype................................

    My requirement is to create an custom  ACCOMDATION type infotype with subtype as 1)temporary 2) Permanent . when user enters the data in the infotype first a popup will come and ask us to select accomdation type......temporary or Permanent. Do i need