954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

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

Hi everyone,

Apparently I'm very bad at this whole programming thing, but, nevertheless, I am currently in a CPS course and in dire need of assistance!

I have 3 objects set up: TwoNumbers, TwoNumbersTester, and Test. When I build the code, it's all fine. When I run the code, though, I get the error shown in the title of this forum post.

Here is my code for TwoNumbers.java:

public class TwoNumbers extends Object                                           // Class header
{
   private double number1;                                                       // Instance variables
   private double number2;
   
      public TwoNumbers( double n1 , double n2 )                                 // Constructor method
      {
      	 number1 = n1;
      	 number2 = n2;
      } 
    
      public void setNums( double n1 , double n2 )                               // Accessor method
         
      {
      	 number1 = n1;
      	 number2 = n2;
      }
      
      public double getSum()                                                     // Accessor method
      {
      	 return number1 + number2;
      }

}

My code for TwoNumbersTester.java:

public class TwoNumbersTester
{

    public TwoNumbersTester() 
    {
    }
    
    public void startTest()
    {
       TwoNumbers equation1;
       TwoNumbers equation2;
       
       equation1 = new TwoNumbers( 10 , 15 );                                // Set numbers for equation
       equation2 = new TwoNumbers( 100 , 200 );
       
       //*** Test first instance of TwoNumbers object ***//
          
       System.out.println( equation1.getSum() );                             // Display sum
          
          
       //*** Test second instance of TwoNumbers object ***//
          
       System.out.println( equation2.getSum() );                             // Display sum
    }

    
}

And, my code for Test.java:

public class Test
{

   public static void main ( double args [] )
   {
      TwoNumbersTester test = new TwoNumbersTester();
      
      test.startTest();
   }
    
}


This is about the trillionth error I've attempted to solve in this program, and it's the last one I'm stuck on. Can anyone help me out? Where is my error? Or, is it not in this code and maybe in one of the other objects?

Thanks so much, in advance, for your help!

petee1302
Newbie Poster
4 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

**I do also just want to add that I'm not looking for a "quick" solution, or a way out of doing my homework. If anyone has help to offer, please explain in a way so that I can understand and learn why whatever I'm doing wrong..is wrong.

Thanks again!!

petee1302
Newbie Poster
4 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

I'm sorry--I forgot to put the code tags in. I can't seem to go back and edit the post to add them, though. I apologize! Here is my code, reposted in tags:

TwoNumbers.java

public class TwoNumbers extends Object // Class header
{
private double number1; // Instance variables
private double number2;

public TwoNumbers( double n1 , double n2 ) // Constructor method
{
number1 = n1;
number2 = n2;
} 

public void setNums( double n1 , double n2 ) // Accessor method

{
number1 = n1;
number2 = n2;
}

public double getSum() // Accessor method
{
return number1 + number2;
}

}


TwoNumbersTester.java

public class TwoNumbersTester
{

public TwoNumbersTester() 
{
}

public void startTest()
{
TwoNumbers equation1;
TwoNumbers equation2;

equation1 = new TwoNumbers( 10 , 15 ); // Set numbers for equation
equation2 = new TwoNumbers( 100 , 200 );

//*** Test first instance of TwoNumbers object ***//

System.out.println( equation1.getSum() ); // Display sum


//*** Test second instance of TwoNumbers object ***//

System.out.println( equation2.getSum() ); // Display sum
}


}


Test.java

public class Test
{

public static void main ( double args [] )
{
TwoNumbersTester test = new TwoNumbersTester();

test.startTest();
}

}


I really appreciate any help anyone has to offer. I'm having a very difficult time catching on to the OOP concept, and I've been digging through my course book, search engines, forums--you name it--with no luck.

petee1302
Newbie Poster
4 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

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

Error description tells you to check signature of main() method.

public class Test
{
   public static void main (<strong>String args[]</strong> ) {
        TwoNumbersTester test = new TwoNumbersTester();
        test.startTest();
   }
}
__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

Thank you--such a simple solution. I figured it out, and when I came back on here, you confirmed it for me. Thanks again!

petee1302
Newbie Poster
4 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: