Main method errors

I am trying to create the Euclid Algorithm in a simple command line application. I get the following error when I try to compile...
Cannot make a static reference to the non-static method getInputs()
Cannot make a static reference to the non-static method doGCD()
Cannot make a static reference to the non-static method doLCM()
public class Euclid
     public static void main(String[] args)
//This is where I try to invoke the methods getInputs(), doGCD(), and doLCM() but it errors.
     public void getInputs()
     {      //User defined inputs
     public void doGCD()     
     {      //Algorithm
     public void doLCM()     
     {      //Algorithm               
Is there a proper way to invoke these because I've been researching and I think I need to create objects, but I'm not sure what that means.

adam.lee wrote:
Try putting your methods outside of the main method. What does that even mean? They are outside the main() method. Unless you mean call them somewhere else, but that doesn't make sense because if you can't call any methods inside the main() method then you can't make your program do anything.
You can call them inside the main method but you might have to put 'static' in front.Terrible advice. You only ever make a method static if it needs to be static. Never, ever, ever, ever, EVER make a method static just for the sake of getting your program to compile. This breeds ignorance of what the term 'static' even means. Only make it static if it should belong to the class, and not an object of the class. A method like getInputs() shouldn't be static because each Euclid object could potentially have it's own inputs.

Similar Messages

  • No main method error

    Hello I'm using net beans v4, and I'm getting an error after I compile and try to run my code
    It says that my .java is missing a main method, I'm lost
    Below is the code. I also have a form.
    I dont know what the main method is or what goes in it.
    (I've tried the beginner tutorial for netbeans which creates a program called colourswitch)
    any help would be appreciated.
    thx
    * user_authorization.java
    * Created on March 6, 2005, 8:19 PM
    * @author BM
    * misrab at mcmaster dot ca
    public class user_authorization extends javax.swing.JPanel {
    /** Creates new form user_authorization */
    public user_authorization() {
    initComponents();
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    private void initComponents() {                         
    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();
    jLabel4 = new javax.swing.JLabel();
    jTextField1 = new javax.swing.JTextField();
    jPasswordField1 = new javax.swing.JPasswordField();
    jButton1 = new javax.swing.JButton();
    setLayout(null);
    jLabel1.setFont(new java.awt.Font("Arial", 1, 18));
    jLabel1.setText("User Authorization");
    add(jLabel1);
    jLabel1.setBounds(120, 50, 170, 22);
    jLabel2.setText("Please enter your user name and password to enter the system.");
    add(jLabel2);
    jLabel2.setBounds(40, 80, 350, 15);
    jLabel3.setText("UserName");
    add(jLabel3);
    jLabel3.setBounds(110, 140, 70, 15);
    jLabel4.setText("PassWord");
    add(jLabel4);
    jLabel4.setBounds(110, 170, 60, 15);
    add(jTextField1);
    jTextField1.setBounds(210, 140, 60, 20);
    add(jPasswordField1);
    jPasswordField1.setBounds(210, 170, 60, 22);
    jButton1.setText("Access System");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton1ActionPerformed(evt);
    add(jButton1);
    jButton1.setBounds(140, 210, 110, 23);
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
    // TODO add your handling code here:
    //Declare the variables
    String strUserName;
    String strPassWord;
    //setting textfield to variable name
    strUserName = jTextField1.getText();
    strPassWord = jPasswordField1.getText();
    for (int i=1; i<=3; i=i+1) {
    // user authentication module
    if (strUserName == "admin" && strPassWord == "smith" || strUserName == "general" && strPassWord == "thesis")
    { //you can enter system
    System.out.println("system access granted");
    else {
    strUserName = null;
    strPassWord = null;
    jPasswordField1.setEnabled(false);
    jTextField1.setEnabled(false);
    jButton1.setEnabled(false);
    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPasswordField jPasswordField1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration
    }

    hmm ok..well I remember seeing that in one of the other versions that I had created of my project
    but it was giving me errors at compile time...it would underline all the code after that line...
    The error was saying that all the labels and command buttons I had on the form (that were automatically put in the code, in that light blue area) didn't have an interface.
    What does that mean?
    thx in advance for your help

  • Com.sun.tools.javac.Main: method compile errors

    I had a working web project the other day, and something happened that caused every page to start throwing this error:
    # javax.servlet.ServletException: com.sun.tools.javac.Main: method compile([Ljava/lang/String;Ljava/io/PrintWriter;)I not found
    # at com.ibm.ws.webcontainer.jsp.servlet.JspServlet.service(JspServlet.java:779)
    # at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    # at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
    # at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
    # at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
    # at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
    # at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
    # at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
    # at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
    # at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:978)
    # at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:564)
    # at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:200)
    # at com.mayco.mvc.MVCServlet.processRequest(MVCServlet.java:426)
    # at com.mayco.ldap.MayServlet.service(MayServlet.java:415)
    # at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
    # at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
    # at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
    # at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
    # at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
    # at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
    # at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
    # at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:76)
    # at com.mayco.cy.filter.AuthenticateFilter.doFilter(AuthenticateFilter.java:167)
    # at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:132)
    # at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:71)
    # at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:974)
    # at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:564)
    # at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:200)
    # at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:119)
    # at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:276)
    # at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
    # at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
    # at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
    # at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
    # at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:618)
    # at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:439)
    # at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:672)
    I tried setting up a clean environment (server, EAR, web project), but haven't been able to re-solve the problem I had with the original project yet.  If I could get a starting point to look for how to solve this type of error it would be greatly appreciated!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    I checked my JDK compliance (1.4) and the installed JREs (Standard VM; WebSphere v5.1 EE JRE; C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51_stub\java\jre)
    I did notice that it was using the JRE System LIbrary [WebSphere v5.1 JRE] and I changed it to the WebSphere v5.1 EE JRE like I think it should have been...
    and the web server startup begins with:
    *** Starting the server ***
    ************ Start Display Current Environment ************
    WebSphere Platform 5.1 [BASE 5.1.0.3 cf30412.02] [JDK 1.4.1 b0344.02] running with process name localhost\localhost\server1 and process id 2692
    Host Operating System is Windows XP, version 5.1
    Java version = J2RE 1.4.1 IBM Windows 32 build cn1411-20031011 (JIT enabled: jitc), Java Compiler = jitc, Java VM name = Classic VM
    was.install.root = C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51
    user.install.root = C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51
    Java Home = C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51\java\jre
    ws.ext.dirs = C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51/java/lib;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51/classes;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51/classes;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51/lib;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51/lib/ext;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51/web/help;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51/deploytool/itp/plugins/com.ibm.etools.ejbdeploy/runtime;C:/Program Files/IBM/SQLLIB/java/db2java.zip;C:/Program Files/IBM/WebSphere Studio/Application Developer/v5.1.2/wstools/eclipse/plugins/com.ibm.etools.webservice_5.1.2/runtime/worf.jar
    Classpath = C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51/properties;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51/properties;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51/lib/bootstrap.jar;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51/lib/j2ee.jar;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51/lib/lmproxy.jar;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51/lib/urlprotocols.jar;C:\WebSphere\properties;C:\spi4j2.5.4_J2ee1.4\clientLib\XEES.jar;C:\spi4j2.5.4_J2ee1.4\clientLib\bcprov-jdk14-139.jar;C:\spi4j2.5.4_J2ee1.4\clientLib\config.jar;C:\spi4j2.5.4_J2ee1.4\clientLib\spi4jStub_2.5.4.jar;C:\spi4j2.5.4_J2ee1.4\clientLib\XEES100J.jar;C:\spi4j2.5.4_J2ee1.4\clientLib\XEES110J.jar;C:\spi4j2.5.4_J2ee1.4\clientLib\XEES120J.jar;C:\spi4j2.5.4_J2ee1.4\clientLib\XEES200J.jar;C:\spi4j2.5.4_J2ee1.4\clientLib\XTCP211.jar;C:\spi4j2.5.4_J2ee1.4\Demo\log4j-1.2.8.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\spi4jCore_2.5.4.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\axis-1.1.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\xmlParserAPIs-2_2_1.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\jaxrpc.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\wsdl4j.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\fsgWsif1.1.jar;C:\spi4j2.5.4_J2ee1.4\Demo\commons-logging.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\tools.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\commons-pool-1.2.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\saaj.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\commons-beanutils-core.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\commons-collections-3.1.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\commons-discovery.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\commons-lang-2.1.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\connector.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\FEDRWSCHECKSTATUSAxisInfo.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\fscontext.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\IFSClassLoader1.2.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\j2ee1.4.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\jca.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\jta.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\mail.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\providerutil.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\qname.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\soaprmi-1_1.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\xalan.jar;C:\spi4j2.5.4_J2ee1.4\coreLib\xercesImpl-2_2_1.jar;C:/Program Files/IBM/WebSphere Studio/Application Developer/v5.1.2/wstools/eclipse/plugins/com.ibm.etools.websphere.tools.common_5.1.1.1/runtime/wteServers.jar;C:/Program Files/IBM/WebSphere Studio/Application Developer/v5.1.2/wstools/eclipse/plugins/com.ibm.etools.websphere.tools.common_5.1.1.1/runtime/wasToolsCommon.jar
    Java Library path = C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51/bin;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51/java/bin;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\runtimes\base_v51/java/jre/bin;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\eclipse\jre\bin;.;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\eclipse\jre\bin;C:\oracle\product\10.2.0\client_2\bin;C:\oracle\product\10.2.0\client_1\bin;Y:\oracle\ora92\BIN;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\PROGRA~1\CA\SHARED~1\SCANEN~1;C:\PROGRA~1\CA\ETRUST~1;C:\PROGRA~1\IBM\SQLLIB\BIN;C:\PROGRA~1\IBM\SQLLIB\FUNCTION;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;C:\Program Files\Rational\common;C:\Program Files\Rational\ClearCase\bin;C:\Program Files\IBM\SDP70\jdk\bin
    ************* End Display Current Environment *************

  • Solution for Windows Store app "projectname.exe" does not contain a static 'Main' method suitable for an entry point . Error.

    Hi,
    I'm developed a blog reader for windows 8 store app. It was perfectly worked before. But suddenly it started to miss behave and I got an
    error. No other errors were there other than that.
    Error 
    Program c:\Users\.........\Desktop\Blog_Reader\Blog_Reader\obj\Release\intermediatexaml\Blog_Reader.exe' does not contain a static 'Main'
    method suitable for an entry point. 
    C:\Users\..........\Desktop\Blog_Reader\Blog_Reader\CSC    Blog_Reader
    But I found the solution while I fixing it.
    Solution for that is like below.
    Go to your App.Xaml and Right-Click thenGo to Properties
    Check whether the Build Action is
    ApplicationDefinition
    If not change it to ApplicationDefinition.
    Clean the code (solution) and Deploy
    Now the error is fiexed.

    Hi Robana, 
    Good sharing on the Technet. 
    This will definitely benefit other who may encounter the same issue as yours.
    Thanks for your sharing again. 
    Kate Li
    TechNet Community Support

  • How do I correct "No Such Method Error: main " ? ? ?

    Dear Java People,
    I have an error message in my program that says
    " No Such Method: main " . How do I correct this problem?
    Thank you in advance
    Stan

    Dear Java People,
    I have an error message in my program that says
    " No Such Method: main " . How do I correct this
    problem? It will be one of the following:
    -You don't have a main method at all
    -You don't have the correct signature for main. For instance it isn't static.
    -You are trying to run the wrong class. The main method is in a different class than the one you are specifying.

  • Bouncing Ball without Main Method

    Hi. I needed to reserch on the Internet sample code for a blue bouncing ball which I did below. However, I try coding a main class to start the GUI applet and it's not working. How can I create the appropriate class that would contain the main method to start this particular application which the author did not provide? The actual applet works great and matches the objective of my research (http://www.terrence.com/java/ball.html). The DefaultCloseOperation issues an error so that's why is shown as remarks // below. Then the code in the Ball.java class issues some warning about components being deprecated as shown below. Thank you for your comments and suggestions.
    Compiling 2 source files to C:\Documents and Settings\Fausto Rivera\My Documents\NetBeansProjects\Rivera_F_IT271_0803B_01_PH3_DB\build\classes
    C:\Documents and Settings\Fausto Rivera\My Documents\NetBeansProjects\Rivera_F_IT271_0803B_01_PH3_DB\src\Ball.java:32: warning: [deprecation] size() in java.awt.Component has been deprecated
        size = this.size();
    C:\Documents and Settings\Fausto Rivera\My Documents\NetBeansProjects\Rivera_F_IT271_0803B_01_PH3_DB\src\Ball.java:93: warning: [deprecation] mouseDown(java.awt.Event,int,int) in java.awt.Component has been deprecated
      public boolean mouseDown(Event e, int x, int y) {
    2 warnings
    import javax.swing.*;
    public class BallMain {
    * @param args the command line arguments
    public static void main(String[] args) {
    Ball ball = new Ball();
    //ball.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    ball.setSize( 500, 175 ); // set frame size
    ball.setVisible( true ); // display frame
    import java.awt.*;*
    *import java.applet.*;
    import java.util.Vector;
    // Java Bouncing Ball
    // Terrence Ma
    // Modified from Java Examples in a Nutshell
    public class Ball extends Applet implements Runnable {
    int x = 150, y = 100, r=50; // Position and radius of the circle
    int dx = 8, dy = 5; // Trajectory of circle
    Dimension size; // The size of the applet
    Image buffer; // The off-screen image for double-buffering
    Graphics bufferGraphics; // A Graphics object for the buffer
    Thread animator; // Thread that performs the animation
    boolean please_stop; // A flag asking animation thread to stop
    /** Set up an off-screen Image for double-buffering */
    public void init() {
    size = this.size();
    buffer = this.createImage(size.width, size.height);
    bufferGraphics = buffer.getGraphics();
    /** Draw the circle at its current position, using double-buffering */
    public void paint(Graphics g) {
    // Draw into the off-screen buffer.
    // Note, we could do even better clipping by setting the clip rectangle
    // of bufferGraphics to be the same as that of g.
    // In Java 1.1: bufferGraphics.setClip(g.getClip());
    bufferGraphics.setColor(Color.white);
    bufferGraphics.fillRect(0, 0, size.width, size.height); // clear the buffer
    bufferGraphics.setColor(Color.blue);
    bufferGraphics.fillOval(x-r, y-r, r*2, r*2); // draw the circle
    // Then copy the off-screen buffer onto the screen
    g.drawImage(buffer, 0, 0, this);
    /** Don't clear the screen; just call paint() immediately
    * It is important to override this method like this for double-buffering */
    public void update(Graphics g) { paint(g); }
    /** The body of the animation thread */
    public void run() {
    while(!please_stop) {
    // Bounce the circle if we've hit an edge.
    if ((x - r + dx < 0) || (x + r + dx > size.width)) dx = -dx;
    if ((y - r + dy < 0) || (y + r + dy > size.height)) dy = -dy;
    // Move the circle.
    x += dx; y += dy;
    // Ask the browser to call our paint() method to redraw the circle
    // at its new position. Tell repaint what portion of the applet needs
    // be redrawn: the rectangle containing the old circle and the
    // the rectangle containing the new circle. These two redraw requests
    // will be merged into a single call to paint()
    repaint(x-r-dx, y-r-dy, 2*r, 2*r); // repaint old position of circle
    repaint(x-r, y-r, 2*r, 2*r); // repaint new position of circle
    // Now pause 50 milliseconds before drawing the circle again.
    try { Thread.sleep(50); } catch (InterruptedException e) { ; }
    animator = null;
    /** Start the animation thread */
    public void start() {
    if (animator == null) {
    please_stop = false;
    animator = new Thread(this);
    animator.start();
    /** Stop the animation thread */
    public void stop() { please_stop = true; }
    /** Allow the user to start and stop the animation by clicking */
    public boolean mouseDown(Event e, int x, int y) {
    if (animator != null) please_stop = true; // if running request a stop
    else start(); // otherwise start it.
    return true;
    }

    FRiveraJr wrote:
    I believe that I stated that this not my code and it was code that I researched.and why the hll should this matter at all? If you want help here from volunteers, your code or not, don't you think that you should take the effort to format it properly?

  • Need help - how to run this particular method in the main method?

    Hi all,
    I have a problem with methods that involves objects such as:
    public static Animal get(String choice) { ... } How do we return the "Animal" type object? I understand codes that return an int or a String but when it comes to objects, I'm totally lost.
    For example this code:
    import java.util.Scanner;
    interface Animal {
        void soundOff();
    class Elephant implements Animal {
        public void soundOff() {
            System.out.println("Trumpet");
    class Lion implements Animal {
        public void soundOff() {
            System.out.println("Roar");
    class TestAnimal {
        public static void main(String[] args) {
            TestAnimal ta = new TestAnimal();
            ta.get(); // error
            // doing Animal a = new Animal() is horrible... :(                   
        public static Animal get(String choice) {
            Scanner myScanner = new Scanner(System.in);
            choice = myScanner.nextLine();
            if (choice.equalsIgnoreCase("meat eater")) {
                return new Lion();
            } else {
                return new Elephant();
    }Out of desperation, I tried "Animal a = new Animal() ", and it was disastrous because an interface cannot be instantiated. :-S And I have no idea what else to put in my main method to get the code running. Need some help please.
    Thank you.

    Hi paulcw,
    Thank you. I've modified my code but it still doesn't print "roar" or "trumpet". When it returns a Lion or an Elephant, wouldn't the soundOff() method get printed too?
    refactored:
    import java.util.Scanner;
    interface Animal {
        void soundOff();
    class Elephant implements Animal {
        public void soundOff() {
            System.out.println("Trumpet");
    class Lion implements Animal {
        public void soundOff() {
            System.out.println("Roar");
    class TestAnimal {
        public static void main(String[] args) {
            Animal a = get();
        public static Animal get() {
            Scanner myScanner = new Scanner(System.in);
            System.out.println("Meat eater or not?");
            String choice = myScanner.nextLine();
            if (choice.equalsIgnoreCase("meat eater")) {
                return new Lion();
            } else {
                return new Elephant();
    }The soundOff() method should override the soundOff(); method in the interface, right? So I'm thinking, it should print either "roar" or "trumpet" but it doesn't. hmm..

  • How to add a code TestIfElse(10) to the Main method of the Program.cs class?

    How to add a code  TestIfElse(10) to the Main method of the Program.cs class?
    Here is my code and I have copied from the Wiley book for Microsoft certification page 14,
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    namespace ifelse_Statement
        class Program
            static void Main(string[] args);
            TestIfElse(10);
            public static void TestIfElse(int n);
            if(n < 10)
                     Console.WriteLine("n is less than 10");
             else if(n < 20)
                    Console.WriteLine("n is less than 20");
             else if(n < 30)
                Console. WriteLine("n is greater than or equal to 30");
    Here is the error list I am getting,
    Error 1      Method must have a return type        C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\switch_Statement\Program.cs
    12 13
    switch_Statement
    Error 2
    Type expected C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\switch_Statement\Program.cs
    12 24
    switch_Statement
    Error 3
    Method must have a return type C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    12 9
    ifelse_Statement
    Error 4
    Type expected C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    12 20
    ifelse_Statement
    Error 5
    Invalid token 'if' in class, struct, or interface member declaration
    C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    16 9
    ifelse_Statement
    Error 6
    Invalid token '10' in class, struct, or interface member declaration
    C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    16 16
    ifelse_Statement
    Error 7
    Type expected C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    16 16
    ifelse_Statement
    Error 8
    Invalid token '(' in class, struct, or interface member declaration
    C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    18 35
    ifelse_Statement
    Error 9
    A namespace cannot directly contain members such as fields or methods
    C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    20 10
    ifelse_Statement
    Error 10
    Type or namespace definition, or end-of-file expected
    C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    30 1
    ifelse_Statement
    Error 11
    The type or namespace name 'n' could not be found (are you missing a using directive or an assembly reference?)
    c:\users\pvs\documents\visual studio 2013\projects\lesson01\ifelse_statement\program.cs
    16 12
    ifelse_Statement
    Error 12
    'System.Console.WriteLine(string, params object[])' is a 'method' but is used like a 'type'
    c:\users\pvs\documents\visual studio 2013\projects\lesson01\ifelse_statement\program.cs
    18 26
    ifelse_Statement

    static void Main(string[] args){
    TestIfElse(10);
    public static void TestIfElse(int n)
    if (n < 10)
    Console.WriteLine("n is less than 10");
    else if (n < 20)
    Console.WriteLine("n is less than 20");
    else if (n < 30)
    Console.WriteLine("n is greater than or equal to 30");
    Fouad Roumieh

  • Calling main method in another class using command line arguements

    Hi
    My program need to use 4 strings command line arguments
    entered in Project properties/Run/Application Parameters
    java programming for beginners // arguments
    The program needs to call main in the second class 4 times using argument 1 the first call, argument 2 the second call on so on.
    So the output wil be
    java
    programming
    for
    beginners
    import java.lang.*;
    public class First extends Second{
      public static void main(String[] args) {
        for(int i = 0; i < args.length; i++){
           Second.main(args); // Error I think
    import java.lang.*;
    public class Second {
    public static void main(String[] args){
    System.out.println(args[0]);
    "First.java": Error #: 300 : method main(java.lang.String) not found in class Second at line 6, column 15
    I am only a beginner with little knowledge of java so can the code be as basic as possible

    Your style looks quite bad for starters..... Hows
    this://import java.lang.*; /* NOT NEEDED */
    public class First extends Second{
    public First(String s) {
    super(s);
    public static void main(String[] args) {
    for(int i = 0; i < args.length; i++){
    new First(s);
    public class Second {
    public Second(String s)
    System.out.println(s);
    NOT NEEDED:
    public static void main(String[] args){
    System.out.println(args[0]);
    }My question to you: Do you understand why my code
    works? (does it do what you want?)I think since this is some kind of lesson, the OP have to implement some way to use the main method of the Second class as it is, that is, with String[] args. I think this lesson is interesting exactly because of this requirenment. But, anyway, I don�t know, that is just my assumption...

  • Does not contain a static 'Main' method suitable for an entry point_

    Hello
    I want to to do a project with Entiity Framework . I add a project to my solution for my domain class and it's name is 'LinkModel.DomainClasses'.  when I prees F5 there is an error like bellow.
    Could You help me to solve this? thanks alot
    ..\Documents\Training\LinkCodeFirstLast\LinkCodeFirst\LinkCodeFirst\LinkModel.DomainClasses\obj\Debug\LinkModel.DomainClasses.exe'
    does not contain a static 'Main' method suitable for an entry point

    Hi bkshn,
    This error is caused by the missing "Main" method in your project. it is the entry point of your project.
    If you want to create a EF project, you could follow the way in the aricle below.
    https://msdn.microsoft.com/en-us/data/ee712907#codefirst
    The Main method is like below.
    class Program
    static void Main(string[] args)
    using (var db = new BloggingContext())
    // Create and save a new Blog
    Console.Write("Enter a name for a new Blog: ");
    var name = Console.ReadLine();
    var blog = new Blog { Name = name };
    db.Blogs.Add(blog);
    db.SaveChanges();
    // Display all Blogs from the database
    var query = from b in db.Blogs
    orderby b.Name
    select b;
    Console.WriteLine("All blogs in the database:");
    foreach (var item in query)
    Console.WriteLine(item.Name);
    Console.WriteLine("Press any key to exit...");
    Console.ReadKey();
    And you could start to learn the EF from the following MSDN blogs.
    https://msdn.microsoft.com/en-us/data/ee712907
    If you have any other concern regarding this issue, please feel free to let me know.
    Best regards,
    Youjun Tang
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Projectname.exe' does not contain a static 'Main' method suitable for an entry point .

    Hi,
    I'm developing a blog reader for windows 8 store app. It was perfectly worked before. But because of some miss behave my coding i get below error. No other errors there.
    Error    1    Program 'c:\Users\.........\Desktop\Blog_Reader\Blog_Reader\obj\Release\intermediatexaml\Blog_Reader.exe' does not contain a static 'Main' method suitable for an entry point    C:\Users\..........\Desktop\Blog_Reader\Blog_Reader\CSC  
     Blog_Reader
    Please help me to figure this.
    Thank You!

    Go to your App.Xaml and R-Click Go to Properties
    Check whether the Build Action is ApplicationDefinition
    If not change it to ApplicationDefinition. Clean the code (solution ) and Deploy..
    Chears....

  • Does main method have to be static? Is there a way to go around it?

    I am trying to write a class that will recursively walk through directory listing of a given ftp adress and store it in a text file in this format:
    <path> , DIR // if directory
    <path> , file // if file
    Since I am not yet experienced to do my own socket programming(tried and did not work out) I used Secure iNet Factory's library. And since I will be running multiple instances of this class I concluded that my fields and methods should not be static. Here is the class I wrote:
    import com.jscape.inet.ftp.Ftp;
    import com.jscape.inet.ftp.FtpException;
    import java.io.BufferedWriter;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.net.URL;
    import java.util.Enumeration;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    public class test {
         private String path = "/";
         private String name;
         private String adres;
         // create new Ftp instance and connect.
         public test(String Name, String Adres) throws IOException {
              name = Name;
              adres = Adres;
              System.out.println("Test class: " + name);
              try {
                   Ftp ftp = new Ftp(adres,"anonymous","anonymous");
                   ftp.connect();
                   Enumeration e = ftp.getDirListing();
                   iterate(path, ftp);
                   ftp.disconnect();
              catch (FtpException ex) {
                   Logger.getLogger(test.class.getName()).log(Level.SEVERE, null, ex);
         void iterate(String aStartingDir, Ftp ftp) throws FtpException, IOException {
              //Set the path.
              path = path + aStartingDir + "/";
              // Change directory.
              ftp.setDir(aStartingDir);
              // Iterate through directory list.
              Enumeration e = ftp.getDirListing();
              while(e.hasMoreElements()){
                   Object f = e.nextElement();
                   // Recursive call if item is directory.
                   if(f.toString().startsWith("drwxrwxrwx") &&
                        // Ignore "." and ".."
                        !f.toString().substring(55).trim().equalsIgnoreCase(".") &&
                        !f.toString().substring(55).trim().equalsIgnoreCase("..")) {
                        // Write to index file.
                        URL dirUrl = FtpCheck.class.getResource("./index/"); // get the directory.
                        URL fileUrl = new URL(dirUrl, name + ".txt"); // construct the file path.
                        String filePath = fileUrl.getPath().replaceAll("%20", " "); // fix spaces.
                        BufferedWriter file = new BufferedWriter(new FileWriter(filePath,true));
                        file.write((path + f.toString().substring(55).trim()).substring(3)
                             + ",DIR\n");
                        file.close();
                        iterate(f.toString().substring(55).trim(),ftp);
                   // Skip entries "." and ".."
                   else if (f.toString().substring(55).trim().equalsIgnoreCase(".") ||
                             f.toString().substring(55).trim().equalsIgnoreCase("..")) {
                             continue;
                   // Add files to the index.
                   else {
                        URL dirUrl = FtpCheck.class.getResource("./index/"); // get the directory.
                        URL fileUrl = new URL(dirUrl, "index.txt"); // construct the file path.
                        String filePath = fileUrl.getPath().replaceAll("%20", " "); // fix spaces.
                        BufferedWriter file = new BufferedWriter(new FileWriter(filePath,true));
                        file.write((path + f.toString().substring(55).trim()).substring(3)
                             + ",file\n");
                        file.close();
              // End of listing reached, go one directory up.
              ftp.setDirUp();
              // And remove the last directory name from path.
              path = path.substring(0,path.lastIndexOf("/"));
              path = path.substring(0,path.lastIndexOf("/")) + "/";
    }which compiles fine.
    Here is the class that invokes it:
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.net.MalformedURLException;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    * @author Sentinel
    public class NewClass {
         public NewClass() {
         public static void main(String args[]) throws MalformedURLException, FileNotFoundException, IOException {
              index t = new index("El Naga","elnaga.sytes.net");
              t.start();
              index t1 = new index("Afacan","afacan.myftp.org");
              t1.start();
         public class index extends Thread {
              String name;
              String adres;
            public index(String Name,String Adres) {
                name = Name;
                adres = Adres;
            @Override
            public void run() {
                try {
                    test checker = new test(name,adres);
                catch (IOException ex) {
                     Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
    }when I hit run build fails:
    init:
    deps-jar:
    Compiling 1 source file to C:\Documents and Settings\Sentinel\My Documents\NetBeansProjects\ftpCheck\build\classes
    C:\Documents and Settings\Sentinel\My Documents\NetBeansProjects\ftpCheck\src\NewClass.java:19: non-static variable this cannot be referenced from a static context
                    index t = new index("El Naga","elnaga.sytes.net");
                              ^
    C:\Documents and Settings\Sentinel\My Documents\NetBeansProjects\ftpCheck\src\NewClass.java:20: non-static variable this cannot be referenced from a static context
                    index t1 = new index("Afacan","afacan.myftp.org");
                               ^
    2 errors
    BUILD FAILED (total time: 0 seconds)I (now)know that main method has to be static. I'm stuck and in need of help to overcome this obstacle. Is there a way to do this?

    a stab in the dark, but what if you make index a non-internal class. make it a stand-alone class in it's own file. Either that or make it a static inner class (almost the same thing).
    Your problem is that an inner class needs an instance of the outer class to start on, and you're not doing this. Another solution would be to do this kludge:
    index t = new NewClass().new index("El Naga","elnaga.sytes.net");  // I think this is how to call itBut again better is to make index a stand-alone class.
    Edited by: Encephalopathic on Oct 28, 2008 8:06 AM

  • Getting missing method error - first attempt at arrays

    I'm trying to work with arrays for the first time ever - I understand the concept, but can't quite get the syntax down. Here is the class which won't compile and is giving me a missing method body or declare abstract message - please help me understand what I'm doing wrong.
    import java.util.Scanner;
    import static java.lang.System.out;
    public class Inventory
      //declare and initialize variables
       private int itemNumber = 0;
       private String productName;
       private int stockAmount = 0;
       private double productCost = 0;
       private double totalValue = 0;
       private double totalInventory = 0;
       //initialize scanner
       Scanner input = new Scanner(System.in);
       public Inventory (int itemNumber, String productName, int stockAmount,
               double productCost, double totalValue);
       out.println("Please enter item number: "); //prompt for item number
          itemNumber = input.nextInt();
       out.println( "Enter product name/description: "); //prompt for product name
          productName = input.next();
       out.println("Quantity in stock: ");
          stockAmount = input.nextInt(); // prompt for stock quantity
       out.println("What is the product cost for each unit? ");
          productCost = input.nextDouble(); // prompt for product cost
            totalValue = stockAmount * productCost; //calculate stock value
          } // end calculate stock value
          { //request for inventory details
            out.printf("%s, which is item number %d, has %d pieces currently in " +
                "stock at a price of %.2f each. The total value of " +
                "inventory in stock is %.2f\n.", productName, itemNumber, +
                stockAmount, productCost, totalValue);
          } // end request
      }// end classHere is my main method - I don't think I'm referencing things the way I'm supposed to.
    public class Main {
      public static void main(String[] args) { //start main method
            Inventory inventory = new Inventory(); //call Inventory class
            inventory.inventoryInput();
    }

    LOL - you are right, I don't really know what I'm doing. I don't understand this and am just trying to muddle my way through this whole thing...as you can tell I'm facing many challenges.
    Here is how I've changed my main method and the Inventory class - still getting error messages though - any additional hints/suggestions?
    Inventory class
    import java.util.Scanner;
    import static java.lang.System.out;
    public class Inventory
      //declare and initialize variables
       private int itemNumber = 0;
       private String productName;
       private int stockAmount = 0;
       private double productCost = 0;
       private double totalValue = 0;
       private double totalInventory = 0;
       //initialize scanner
       Scanner input = new Scanner(System.in);
       public Inventory (int itemNumber, String productName, int stockAmount,
               double productCost, double totalValue)
       out.println("Please enter item number: "); //prompt for item number
          itemNumber = input.nextInt();
       out.println( "Enter product name/description: "); //prompt for product name
          productName = input.next();
       out.println("Quantity in stock: ");
          stockAmount = input.nextInt(); // prompt for stock quantity
       out.println("What is the product cost for each unit? ");
          productCost = input.nextDouble(); // prompt for product cost
            totalValue = stockAmount * productCost; //calculate stock value
          } // end calculate stock value
          { //request for inventory details
            out.printf("%s, which is item number %d, has %d pieces currently in " +
                "stock at a price of %.2f each. The total value of " +
                "inventory in stock is %.2f\n.", productName, itemNumber, +
                stockAmount, productCost, totalValue);
          } // end request
      }// end classMain method
    public class TestInventory
        public static void main(String[] args)
        {Inventory[] inventoryArray = new Inventory[3];
         inventoryArray[0] = new Inventory(0, 2541, Radios, 14, 15.95);
         inventoryArray[1] = new Inventory(1, 1685, VCR, 10, 98.95);
         inventoryArray[2] = new Inventory(2, 5872, Clock, 8, 12.95);
         For (Inventory inventory : inventoryArray)
             System.out.println(Inventory);
    }

  • How to increase the Java Heap Space for a main method

    Hello all,
    after a given number of calculations inside a class with main-method, I get an OutOfMemoryError (Java Heap Size).
    So I'm just trying to increase the Heap Size Creator uses, but it won't work.
    After reading a lot of posts and online-articles, I tried the following:
    1) I changed the -Xms and -Xmx options (to 512m) both in
    $CREATOR/SunAppServer8/domains/creator/config/domain.xml and
    $CREATOR/etc/creator.conf (this file also points to the Creator built-in JDK)
    2) additionally I tried to start Creator from the console with the respective option:
    ./creator -J-Xmx512m
    The memory toolbar shows the right value, but when I use
    System.out.println("JVM maximum memory:\t"+Runtime.getRuntime().maxMemory()/1024+" KB\n");it always says 64 MB, no matter which option I chose in the config-files.
    So how can I increase this value?
    Regards,
    Felix
    Message was edited by:
    Felice
    Message was edited by:
    Felice

    Thank you very much,
    this was an important hint. Additionally I had to create a new "Java Class Library" project with a copy of the needed files (those that are not dependent on the Application Server). Then I could use the option you mentioned.
    Unfortunately, when I try to run the file with
    java -jar FILENAME.jarit won't work, because the archive is not complete: MANIFEST.MF lacks the main-class and all involved libraries.
    I managed to add the main-class attribute manually, but adding all library references seems to be very error-prone.
    So does anyone know if I did something wrong or if this is a bug of Creator?
    Regards,
    Felix

  • Where to put main method ?

    I am working on a small factorial problem and keep recieving Exeption in thread "main" java.lang.NoSuchMethod: main error
    I know my class is missing the public static void main(String[] args) method but since i am used to using Blue J and have now moved to SDK im not sure how to implement the main method into my current program
    I would appreciate any help, current program is :
    public class Factorial
    private int total;
    private int temp;
    private int counter;
    public Factorial(int factor)
    counter = factor;
    total = factor;
    Calculation();
    public void Calculation()
    if(counter > 1){
    temp = counter - 1;
    total = (total * temp);
    counter = temp;
    Calculation();
    else{
    System.out.println(total);
    }

    Sorry i should have explained a little better
    i have to create to new programs, one iterative and one recursive for calculating : fac(n) = n * (n -1) * (n-2) * (n-3) ... till n = 1
    the program does its job properly when run in Blue J (the whole reason for this stupid programme is to practice using SDK instead of Blue J funny enough)
    im still working through it and hope to solve it on my own (for the sake of pride more than anything ) but i have a limit and im really struggling with using this new main method .
    Really appreciatte any help and thanks for it so far

Maybe you are looking for

  • Report needed containing dependent/beneficiary info

    Hi Gurus, Is there a standard report where I could pull in dependent/beneficiary names, SSN and Date of Birth? Please advise

  • Icons in menu bar gone

    All the icons in the menu bar on the top right have disappeared. Time, airport status, time machine, battery status, everything. I've gone into system preferences and tried to set the icon to show up, but it resets itself to the off status when I cli

  • TS1424 not sure how to get my downloads re-downloaded case # 335038589 Help!!

    i downloaded three album and they they skip and stop.

  • Help in update instruction, please

    hi, i can't make progress in my update instruction and need some help. Oracle makes an ora-00907 message and says that a bracket is missing but in this case it doesn't make sense. update DM_MESSDATEN set DM_MESSDATEN.FAUNA_ID=1 where MISSION_ID in (s

  • Simple caching in singleton DAO

    Suppose I was to use a DAO like this in a web application. Different threads would be concurrently accessing this code from different servlets, struts actions, JSP pages, whatever. import java.util.Map; import java.util.HashMap; public class CacheSin