troubleshooting Question

class does not have a main method

Avatar of nsamri
nsamri asked on
Web Graphics SoftwareProgrammingJava
20 Comments3 Solutions5936 ViewsLast Modified:
Hello,
I have a java package conatain three files. I compiled this package correctly using Netbeans V.6. When I run each file in the package, it gives me a message
 "class org.bluer.cg.filename does not have a main method"!!!

Can anyone help me?

I attached just two files to look at them.
(1)
package org.bluear.cg.hull;

import java.awt.geom.Point2D;
import java.util.Collection;
import java.util.List;

/**
 * Defines a generic convex hull algorithm.
 *
 *
 */
public abstract class HullAlgorithm {
   
    // -------------------------------------------------------------------------
    // Constants
    // -------------------------------------------------------------------------
   
    /**
     * Indicates that the given point is to the left of the segment.
     */
    public static final int LEFT = 0;
   
    /**
     * Indicates that the given point is to the right of the segment.
     */
    public static final int RIGHT = 1;
   
    /**
     * Indicates that the given point is beyond the segment.
     */
    public static final int BEYOND = 2;
   
    /**
     * Indicates that the given point is behind the segment.
     */
    public static final int BEHIND = 3;
   
    /**
     * Indicates that the given point is between the segment end points.
     */
    public static final int BETWEEN = 4;
   
    /**
     * Indicates that the given point is at the origin of the segment.
     */
    public static final int ORIGIN = 5;
   
    /**
     * Indicates that the given point is at the destination of the segment.
     */
    public static final int DESTINATION = 6;

    // -------------------------------------------------------------------------
    // Methods
    // -------------------------------------------------------------------------
   
    /**
     * Returns the array of indices of points that are part of the convex
     * hull.
     *
     * @param points A collection of <code>Point2D</code> objects.
     * @return The list of points that are vertices of a convex hull.
     */
    public abstract List getHullPoints(Collection points);
   
    // -------------------------------------------------------------------------
    // Helper methods
    // -------------------------------------------------------------------------
   
    /**
     * Classifies the location of the point (x2, y2) relatively to the segment
     * defined by points (x0, y0) and (x1, y1). The following illustrates
     * regions considered by this method:
     * <pre>
     *
     *           LEFT
     *                         BEYOND
     *                          .
     *                     DESTINATION
     *                        /
     *                    BETWEEN          
     *                      /             RIGHT
     *                  ORIGIN
     *                 .
     *          BEHIND
     * </pre>
     * @param x0 The x of the starting point of the segment.
     * @param y0 The y of the starting point of the segment.
     * @param x1 The x of the final point of the segment.
     * @param y1 The y of the final point of the segment.
     * @param x2 The x of the point whose position we are testing.
     * @param y2 The y of the point whose position we are testing.
     */
    public static int classify(double x0, double y0,
                               double x1, double y1,
                               double x2, double y2) {
        double dx1 = x1 - x0;
        double dx2 = x2 - x0;
        double dy1 = y1 - y0;
        double dy2 = y2 - y0;
        double sa = dx1 * dy2 - dx2 * dy1;
       
        if (sa > 0.0) {
            return (LEFT);
        }
       
        if (sa < 0.0) {
            return (RIGHT);
        }
       
        if (dx1 * dx2 < 0.0 || dy1 * dy2 < 0.0) {
            return (BEHIND);
        }
       
        if (dx1 * dx1 + dy1 * dy1 < dx2 * dx2 + dy2 * dy2) {
            return (BEYOND);
        }
       
        if (x2 == x0 && y2 == y0) {
            return (ORIGIN);
        }
       
        if (x2 == x1 && y2 == y1) {
            return (DESTINATION);
        }

        return (BETWEEN);                
    }

    /**
     * Returns a code indicating where point <code>c</code> is located with
     * respect to the segment formed by points <code>a</code> and <code>b</code>.
     *
     * @param a The first point of the segment.
     * @param b The second point of the segment.
     * @param c The point classified with respect to the segment.
     * @return The code indicating the relative location of c.
     */    
    public static int classify(Point2D a, Point2D b, Point2D c) {
        return (classify(a.getX(), a.getY(), b.getX(), b.getY(), c.getX(), c.getY()));
    }
   
    /**
     * Returns whether or not the tree given points are co-linear.
     *
     * @param p1 The first point.
     * @param p2 The second points.
     * @param p3 The third point.
     * @return Whether or not the three points are co-linear.
     */
    public static boolean colinear(Point2D p1, Point2D p2, Point2D p3) {
        return (p1.getX()*(p2.getY() - p3.getY())
                + p2.getX()*(p3.getY() - p1.getY())
                + p3.getX()*(p1.getY() - p2.getY())) == 0.0;
    }
}

(2)

package org.bluear.cg.hull;

import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;


public class GrahamScanHull extends HullAlgorithm {

      public List getHullPoints(Collection points) {
        int i;
       
        // deal with abnormal cases first ...
        if (points == null || points.size() <= 0) {
            return (Collections.EMPTY_LIST);
        }
       
        int n = 0;
       
        // count the non-null points ...
        for (Iterator iter = points.iterator(); iter.hasNext(); ) {
            Object obj = iter.next();
           
            if (obj instanceof Point2D) {
                ++ n;
            }
        }
       
        if (n <= 0) {
            return (Collections.EMPTY_LIST);
        }
       
        Point2D[] pt = new Point2D[n];
        i = 0;
       
        for (Iterator iter = points.iterator(); iter.hasNext(); ) {
            Object obj = iter.next();
           
            if (obj instanceof Point2D) {
                pt[i ++] = (Point2D) obj;
            }
        }
       
        ArrayList hull = new ArrayList();

        // Graham scan does not do too well if there are only 1 or 2 points ...
        if (n < 3) {
            hull.add(pt[0]);
           
            if (n == 2) {
                hull.add(pt[1]);            
            }
        }
        else {
       
            // Step 1: find extreme point p0
            int m = 0;
            Point2D pi, p0 = pt[0];
       
            for (i = 1; i < n; i++) {
                pi = pt[i];
           
                if (pi.getY() < p0.getY() || (pi.getY() == p0.getY() && pi.getX() < p0.getX())) {
                    m = i;
                    p0 = pi;
                }
            }
       
            if (m != 0) {
                pt[m] = pt[0];
                pt[0] = p0;
            }
       
            // Step 2: sort points by their polar coordinate relative to p0
            Arrays.sort(pt, 1, n, new PolarComparator(p0));
       
            // Step 3: Find the second point of the hull ...
            i = 1;
       
            while (i+1 < n && colinear(p0, pt[i], pt[i+1])) {
                ++ i;
            }
       
            hull.add(p0);
            hull.add(pt[i]);
       
            // Step 4: Grow the current hull until it includes all points
            for (i = i + 1; i < n; ++ i) {
                pi = pt[i];
                Point2D p1 = (Point2D) hull.get(hull.size() - 1);
                p0 = (Point2D) hull.get(hull.size() - 2);
           
                while (LEFT != classify(p0, p1, pi)) {
                    p1 = p0;
                    hull.remove(hull.size() - 1);
                    p0 = (Point2D) hull.get(hull.size() - 2);
                }
           
                hull.add(pi);
            }
        }

            return (hull);
      }

    /**
     * Local class used by the sort method to classify points based on their
     * polar coordinates with respect to the specified pivot point, p0.
     *
     * @author Bo Majewski
     */
    private static class PolarComparator implements Comparator {
       
        private Point2D p0;
       
        /**
         * Creates a new comparator that used the given pivot point.
         *
         * @param p0 The pivot point.
         */
        public PolarComparator(Point2D p0) {
            this.p0 = p0;
        }

            /**
             * Compares object o1 to object o2. This method returns a negative
         * value if o1 lies to the left of o2 with respect to the pivot p0.
         *
             * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
             */
            public int compare(Object o1, Object o2) {
            Point2D p1 = (Point2D) o1;
            Point2D p2 = (Point2D) o2;
           
            // take care of degenerate cases first ...
            if (p1.equals(this.p0)) {
                return (p2.equals(this.p0)? 0 : -1);
            }
           
            if (p2.equals(this.p0)) {
                return (1);
            }
           
            // this is when neither p1 nor p2 is identical to pivot ...
            double d = ((p2.getX() - p0.getX())*(p1.getY() - p0.getY())
                       - (p1.getX() - p0.getX())*(p2.getY() - p0.getY()));
           
            return (d < 0.0? -1 : d > 0.0? 1 : 0);
            }
    }
}
ASKER CERTIFIED SOLUTION
sciuriware

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 3 Answers and 20 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 20 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros