6 Replies - 423 Views - Last Post: 04 May 2011 - 03:25 PM Rate Topic: -----

#1 laytonsdad  Icon User is offline

  • Cheese and Sprinkles
  • member icon

Reputation: 436
  • View blog
  • Posts: 1,851
  • Joined: 30-April 10

Error when ran but not when built

Posted 03 May 2011 - 09:40 PM

what is this mean when I can build it with no errors but cant run

error:
java.lang.NoClassDefFoundError: rectangleclass/Main
Caused by: java.lang.ClassNotFoundException: rectangleclass.Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: rectangleclass.Main. Program will exit.
Exception in thread "main" Java Result: 1

Is This A Good Question/Topic? 0
  • +

Replies To: Error when ran but not when built

#2 Luckless  Icon User is offline

  • </luck>
  • member icon

Reputation: 292
  • View blog
  • Posts: 1,146
  • Joined: 31-August 09

Re: Error when ran but not when built

Posted 03 May 2011 - 09:41 PM

Where are your outside classes at?

This post has been edited by Luckless: 03 May 2011 - 09:42 PM

Was This Post Helpful? 0
  • +
  • -

#3 laytonsdad  Icon User is offline

  • Cheese and Sprinkles
  • member icon

Reputation: 436
  • View blog
  • Posts: 1,851
  • Joined: 30-April 10

Re: Error when ran but not when built

Posted 03 May 2011 - 09:51 PM

I dont know im new to this

all my classes are in the same project and package

its very small will it help to post it?

package rectangleclass;

/**
 *
 * Author: Dustin Parker
 */
public class Rectangle {
    private double length = 1;
    private double width = 1;
    private double area;
    private double perimiter;

    public double getLength() {
        return length;
    }

    public void setLength(double length) {
        if (length>0.0 || length<20.0)
        {
            this.length = length;
        }
    }

    public double getWidth() {
        return width;
    }

    public void setWidth(double width) {
        if(width>0.0 || width<20.0)
        {
            this.width = width;
        }
    }

    public void findArea()
    {
        area=this.length*this.width;
        System.out.printf("With a length of %s and a width of %s the area is %s",
                this.length, this.width, area);
    }

    public void findPerimiter()
    {
        perimiter=(this.length*2)+(this.width*2);
        System.out.printf("With a length of %s and a width of %s the perimeter is %s",
                this.length, this.width, perimiter);
    }
}




package rectangleclass;
import java.util.Scanner;
/**
 *
 * @author Administrator
 */
public class testRectangle {
    public static void testRectangle(String[] args)
    {
        //create scanner
        Scanner input = new Scanner(System.in);
        //create new rectangle object
        Rectangle rec1 = new Rectangle();


        //set length
        System.out.print("Please enter a length: ");
        double length = input.nextDouble();
        rec1.setLength(length);

        //set width
        System.out.print("Please enter a width: ");
        double width = input.nextDouble();
        rec1.setWidth(width);

        //find area
        rec1.findArea();

        //find perimiter
        rec1.findPerimiter();

    }

}


Was This Post Helpful? 0
  • +
  • -

#4 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: Error when ran but not when built

Posted 04 May 2011 - 01:17 AM

The entry point for a Java program is a main() method that must have the signature:

public static void main( String[] args )

I suggest your testRectangle() method should be your main() method.
Was This Post Helpful? 0
  • +
  • -

#5 v0rtex  Icon User is offline

  • Caffeine: db "Never Enough!"
  • member icon

Reputation: 223
  • View blog
  • Posts: 773
  • Joined: 02-June 10

Re: Error when ran but not when built

Posted 04 May 2011 - 06:05 AM

java.lang.NoClassDefFoundError: rectangleclass/Main

Is just basically the compiler telling you that there is no main method, as GregBrannon suggested make your testRectangle class your main method, like so:
public static void testRectangle(String[] args)


Should become
public static void main(String[] args)


This post has been edited by v0rtex: 04 May 2011 - 06:07 AM

Was This Post Helpful? 0
  • +
  • -

#6 cfoley  Icon User is online

  • Cabbage
  • member icon

Reputation: 1954
  • View blog
  • Posts: 4,055
  • Joined: 11-December 07

Re: Error when ran but not when built

Posted 04 May 2011 - 06:28 AM

If you make that your main method you will have to run it with

java testRectangle

Was This Post Helpful? 1
  • +
  • -

#7 laytonsdad  Icon User is offline

  • Cheese and Sprinkles
  • member icon

Reputation: 436
  • View blog
  • Posts: 1,851
  • Joined: 30-April 10

Re: Error when ran but not when built

Posted 04 May 2011 - 03:25 PM

thank you all for your help I over looked the main being missing.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1