This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Error: Main method not found Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error: Main method not found" Watch "Error: Main method not found" New topic
Author

Error: Main method not found

Adnan Alvee
Greenhorn

Joined: Feb 01, 2013
Posts: 11
Main Assignment: Write a class named Rectangle to represent rectangles. The data fields are width, height, and color. Use double for width and height, and String for color. Suppose that all the rectangles are the same color. You need to provide the accessor methods for the properties and a findArea() method for computing the area of the rectangle.
Write a client program(test class) to test the class Rectangle. In the client program, create two Rectangle objects. Assign any width and height to the two objects. Assign the first object the color red, and the second, yellow. Display the properties of both objects and find their areas.

Error: Main method not found in class Rectangle, please define the main method as:
public static void main(String[] args)
Java Result: 1



Java Code:

Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 613
Error: Main method not found in class Rectangle


your answer is in error log, jvm is trying to find main method in Rectangle class where as it lives in Test class so you must be executing Rectangle instead of Test.

Also, I think you have defined Test class in Rectangle.java file, though its legal but very lazy practice so create new Test.java file and define public Test class in it and execute it.

Cheers
-P


All desirable things in life are either illegal, banned, expensive or married to someone else !!!
Adnan Alvee
Greenhorn

Joined: Feb 01, 2013
Posts: 11
Praful Thakare wrote:
Error: Main method not found in class Rectangle


your answer is in error log, jvm is trying to find main method in Rectangle class where as it lives in Test class so you must be executing Rectangle instead of Test.

Also, I think you have defined Test class in Rectangle.java file, though its legal but very lazy practice so create new Test.java file and define public Test class in it and execute it.

Cheers
-P


Thanks, got rid of the error.
But I am not getting the desired outpur, cannot dsiplay color and area. Output is 1.0 and 1.0 in the first two lines respectively. Can you help kindly?
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 613
But I am not getting the desired outpur


to get desired output you need to give correct input to system.out.println, check what are the arguments to system.out and think what they should be.

Cheers
-P
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 613
let me help with 2nd problem as its a typo, you are getting 1.0 and 1.0 because you used mr.findArea(); in area2 instead of mr2.findArea();
Adnan Alvee
Greenhorn

Joined: Feb 01, 2013
Posts: 11
Praful Thakare wrote:
But I am not getting the desired outpur


to get desired output you need to give correct input to system.out.println, check what are the arguments to system.out and think what they should be.

Cheers
-P


hahhaha. As you can see its area1 and area2 which should be giving me the outputs in the test class but I dont know why its giving me 1!
Adnan Alvee
Greenhorn

Joined: Feb 01, 2013
Posts: 11
Praful Thakare wrote:let me help with 2nd problem as its a typo, you are getting 1.0 and 1.0 because you used mr.findArea(); in area2 instead of mr2.findArea();


Thanks but I get the same thing!
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 613
:-) yes you would, as I said, you need to look at system.out.println.
Adnan Alvee
Greenhorn

Joined: Feb 01, 2013
Posts: 11
Praful Thakare wrote::-) yes you would, as I said, you need to look at system.out.println.


I have no idea right, out of scope in my brain to think about it. If you could, very very new to Java!
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Adnan Alvee wrote:
Praful Thakare wrote::-) yes you would, as I said, you need to look at system.out.println.


I have no idea right, out of scope in my brain to think about it. If you could, very very new to Java!


Your unusual and inconsistent indentation makes your code very hard to read. It should be a consistent 2-4 spaces per level, and it should use spaces, never tabs.

I don't really understand what problem you're having, but if your code is not behaving the way you expect it to, add a bunch of print statements that show which code is executing and what various important values are. Compare that output to what you expect to be happening at each step, and where the expected behavior differs from the observed behavior, that's where you start looking for your bugs.
Adnan Alvee
Greenhorn

Joined: Feb 01, 2013
Posts: 11
Jeff Verdegan wrote:
Adnan Alvee wrote:
Praful Thakare wrote::-) yes you would, as I said, you need to look at system.out.println.


I have no idea right, out of scope in my brain to think about it. If you could, very very new to Java!


Your unusual and inconsistent indentation makes your code very hard to read. It should be a consistent 2-4 spaces per level, and it should use spaces, never tabs.

I don't really understand what problem you're having, but if your code is not behaving the way you expect it to, add a bunch of print statements that show which code is executing and what various important values are. Compare that output to what you expect to be happening at each step, and where the expected behavior differs from the observed behavior, that's where you start looking for your bugs.


Okay I am explaining it again, here is my rectangle class code, I have rearranged them again




Here is the Test Class




So what I want is display an area by inputting different width and height in 'Test Rectangle' class, as you can see I have already done that, but all I am getting is the default values set in 'Rectangle' class
. There are no errors in Netbeans, I am getting the output but its not what I expected.

As you said to use different print statements, I have actually nothing to print, tried but error shows up in rectangle class
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Adnan Alvee wrote:
As you said to use different print statements, I have actually nothing to print,


Sure you do. For starters, you could do this:


tried but error shows up in rectangle class


If you want help with that, you need to show what you tried, copy/paste the exact, complete error message, and indicate clearly exactly which line caused it.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Also, can you describe exactly what you think this does:


Adnan Alvee
Greenhorn

Joined: Feb 01, 2013
Posts: 11
Jeff Verdegan wrote:Also, can you describe exactly what you think this does:




This is the output I am getting

1. 3.0
2. 6.0
3. 3.0
4. 6.0
5. 6.0
6. 6.0

I have changed the intial height and width values to 3 and 2 respectively.
Following your steps, I get 'double' outputs in the first 4 line (Didn't print width though) and I don't know why. Its outputting height and area 2 times!!!

The 5th and 6th line is from Test Class print, so you see its nit taking in my values I set in test class, just outputting default values for both area 1 and area 2!
Adnan Alvee
Greenhorn

Joined: Feb 01, 2013
Posts: 11
Adnan Alvee wrote:
Jeff Verdegan wrote:Also, can you describe exactly what you think this does:




This is the output I am getting

1. 3.0
2. 6.0
3. 3.0
4. 6.0
5. 6.0
6. 6.0

I have changed the intial height and width values to 3 and 2 respectively.
Following your steps, I get 'double' outputs in the first 4 line (Didn't print width though) and I don't know why. Its outputting height and area 2 times!!!

The 5th and 6th line is from Test Class print, so you see its nit taking in my values I set in test class, just outputting default values for both area 1 and area 2!




And also about Param. I dont why I did tha, copy pasted code!
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Sorry, but I have no idea what you're trying to say at this point. If you still have a question, please post your current code, and indicate clearly what inputs are causing what outputs, and ask a clear, concise question.

Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error: Main method not found
 
Similar Threads
I have a program that was working but isn't doing so now...
Rectangle error
compareTo ( ) object
How to fix error in Rectangle Class problem in Java?
Rectangle Class Assignment-need help