[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

java.lang.NoSuchMethodError: main Error occuring when trying to execute some code

Posted on 2004-03-22
15
Medium Priority
?
462 Views
Last Modified: 2007-12-19
// i cant get this program to execute on my computer. Other programs compile without a problem. I have the same problem with another important program.


import java.applet.*;
import java.awt.*;

public class Viewport extends Applet {
    Polygon poly;
    Rectangle viewport = new Rectangle(50, 50, 100, 100);
    EdgeTable et;
    Graphics gr;
    boolean motion = false;
    Point prev;

    static final int LEFT = 0;
    static final int RIGHT = 1;
    static final int TOP = 2;
    static final int BOTTOM = 3;

    public void init() {
      setBackground(Color.white);
      gr = getGraphics();

      poly = new Polygon();

      String str;

      if ((str = getParameter("viewport_x")) != null) {
          viewport.x = Integer.parseInt(str);
      }
      if ((str = getParameter("viewport_y")) != null) {
          viewport.y = Integer.parseInt(str);
      }
      if ((str = getParameter("viewport_width")) != null) {
          viewport.width = Integer.parseInt(str);
      }
      if ((str = getParameter("viewport_height")) != null) {
          viewport.height = Integer.parseInt(str);
      }
    }
   
    public void start() {
        poly = new Polygon();
      et = null;
    }

    /**
     * Clips polygon by viewport.
     */
    void clipping() {
      clipByLine(viewport.x, LEFT);
      clipByLine(viewport.x+viewport.width, RIGHT);
      clipByLine(viewport.y, TOP);
      clipByLine(viewport.y+viewport.height, BOTTOM);
    }

    /**
     * Clips polygon by virtical or horizontal line.
     */
    void clipByLine(int val, int edge) {
      Polygon newPoly = new Polygon();
      boolean inside;
      Point cross;

      inside = insideArea(poly.xpoints[0], poly.ypoints[0], val, edge);

      for (int i = 1; i < poly.npoints; i++) {
          if (insideArea(poly.xpoints[i], poly.ypoints[i], val, edge)) {
            if (inside) {
                newPoly.addPoint(poly.xpoints[i], poly.ypoints[i]);
            } else {
                cross = getCrossing(poly.xpoints[i-1], poly.ypoints[i-1],
                              poly.xpoints[i], poly.ypoints[i],
                              val, edge);
                newPoly.addPoint(cross.x, cross.y);
                newPoly.addPoint(poly.xpoints[i], poly.ypoints[i]);
            }
            inside = true;
          } else {
            if (inside) {
                cross = getCrossing(poly.xpoints[i-1], poly.ypoints[i-1],
                              poly.xpoints[i], poly.ypoints[i],
                              val, edge);
                newPoly.addPoint(cross.x, cross.y);
            }
            inside = false;
          }
      }

      // Makes a polygon be a circuit
      newPoly.addPoint(newPoly.xpoints[0], newPoly.ypoints[0]);

      poly = newPoly;
    }

    /**
     * Determines whether point (x,y) is inside area.
     * Expresses a clipping line with val and edge.
     */
    boolean insideArea(int x, int y, int val, int edge) {
      switch (edge) {
      case LEFT:
          if (x >= val) {
            return true;
          }
          break;
      case RIGHT:
          if (x <= val) {
            return true;
          }
          break;
      case TOP:
          if (y >= val) {
            return true;
          }
          break;
      case BOTTOM:
          if (y <= val) {
            return true;
          }
          break;
      }

      return false;
    }

    /**
     * Gets crossing point between a line of polygon and a clipping line.
     */
    Point getCrossing(int x1, int y1, int x2, int y2, int val, int edge) {
      Point cross = new Point(0, 0);

      switch (edge) {
      case LEFT:
      case RIGHT:
          cross.x = val;
          cross.y = ((y1-y2)*val+(x1*y2-x2*y1))/(x1-x2);
          break;
      case TOP:
      case BOTTOM:
          cross.x = ((x1-x2)*val-(x1*y2-x2*y1))/(y1-y2);
          cross.y = val;
          break;
      }
      
      return cross;
    }

    /**
     * Paint viewport frame and clipped polygon.
     */
    public void paint(Graphics g) {
      g.drawRect(viewport.x, viewport.y, viewport.width, viewport.height);
      g.drawPolygon(poly);
      if (et != null) {
          et.paint(g);
      }
    }

    public boolean mouseDown(Event ev, int x, int y) {
      // Do Clipping when push right button (or META + left button)
      if (ev.metaDown()) {
          motion = false;
          poly.addPoint(poly.xpoints[0], poly.ypoints[0]);
          clipping();
          et = new EdgeTable(poly);
          repaint();
      } else {
          motion = true;
          poly.addPoint(x, y);
          
          if (poly.npoints >= 2) {
            gr.drawLine(poly.xpoints[poly.npoints-2],
                      poly.ypoints[poly.npoints-2], x, y);
          }
      }

      return true;
    }
   
    public boolean mouseMove(Event ev, int x, int y) {
      if (motion) {
          if (poly.npoints >= 1) {
            gr.setXORMode(Color.white);
            gr.drawLine(poly.xpoints[poly.npoints-1],
                      poly.ypoints[poly.npoints-1], prev.x, prev.y);
            gr.drawLine(poly.xpoints[poly.npoints-1],
                      poly.ypoints[poly.npoints-1], x, y);
            gr.setPaintMode();
          }
      }
      prev = new Point(x, y);

      return true;
    }

    /**
     * Info.
     */
    public String getAppletInfo() {
      return "Disignation of a viewport, clipping of a polygon, and painting";
    }

    /**
     * Parameter Info.
     */
    public String[][] getParameterInfo() {
      String[][] info = {
          {"viewport_x",      "integer", "x of the viewport"},
          {"viewport_y",      "integer", "y of the viewport"},
          {"viewport_width",  "integer", "width of the viewport"},
          {"viewport_height", "integer", "height of the viewport"},
      };
      
      return info;
    }
}

/**
 * Edge table for y-sort.
 */
class EdgeTable {
    int xmin[], ymin[], ymax[];
    double invM[];
    int nsize = 0;

    static final int MIN = 0;
    static final int MID = 1;
    static final int MAX = 2;

    EdgeTable(Polygon poly) {
      xmin = new int[poly.npoints-1];
      ymin = new int[poly.npoints-1];
      ymax = new int[poly.npoints-1];
      invM = new double[poly.npoints-1];
      
      for (int i = 0; i < poly.npoints-1; i++) {
          if (poly.ypoints[i] < poly.ypoints[i+1]) {
            xmin[nsize] = poly.xpoints[i];
            ymin[nsize] = poly.ypoints[i];
            ymax[nsize] = poly.ypoints[i+1];
          } else {
            xmin[nsize] = poly.xpoints[i+1];
            ymin[nsize] = poly.ypoints[i+1];
            ymax[nsize] = poly.ypoints[i];
          }
          
          if (poly.ypoints[i] != poly.ypoints[i+1]) {
            invM[nsize] = (double)(poly.xpoints[i]-poly.xpoints[i+1])/
                          (poly.ypoints[i]-poly.ypoints[i+1]);
            nsize++;
          }
      }

      ySort();
    }

    /**
     * Y-sort
     */
    void ySort() {
      for (int i = 0; i < nsize; i++) {
          for (int j = 0; j < nsize-i-1; j++) {
            if (ymin[j] > ymin[j+1]) {
                swap(j, j+1);
            }
          }
      }
    }

    /**
     * Swaps table contents.
     */
    void swap(int i, int j) {
      int temp;
      double tempd;

      temp = xmin[i];
      xmin[i] = xmin[j];
      xmin[j] = temp;

      temp = ymin[i];
      ymin[i] = ymin[j];
      ymin[j] = temp;

      temp = ymax[i];
      ymax[i] = ymax[j];
      ymax[j] = temp;

      tempd = invM[i];
      invM[i] = invM[j];
      invM[j] = tempd;
    }

    /**
     * Paint clipped polygon.
     */
    public void paint(Graphics g) {
      double xpoints[] = new double[nsize];
      int vertex[] = new int[nsize];
      double x[] = new double[nsize];

      for (int i = 0; i < nsize; i++) {
          x[i] = xmin[i];
      }

      for (int scanline = ymin[0]; ; scanline++) {
          int npoints = 0;

          for (int i = 0; i < nsize; i++) {
            if (scanline > ymin[i] && scanline < ymax[i]) {
                if (insert(xpoints, vertex, x[i], MID, npoints)) {
                  npoints++;
                }
                x[i] += invM[i];
            } else if (scanline == ymin[i]) {
                if (insert(xpoints, vertex, x[i], MIN, npoints)) {
                  npoints++;
                }
                x[i] += invM[i];
            } else if (scanline == ymax[i]) {
                if (insert(xpoints, vertex, x[i], MAX, npoints)) {
                  npoints++;
                }
                x[i] += invM[i];
            }
          }
          
          if (npoints == 0) {
            break;
          }
      
          for (int i = 0; i < npoints; i += 2) {
            g.drawLine((int)xpoints[i], scanline,
                     (int)xpoints[i+1], scanline);
          }
      }

      xpoints = null;
    }

    /**
     * Inserts xmin in xpoints[] and attr (MAX,MID,MIN) in vertex[].
     * Return true if success an insertion.
     */
    boolean insert(double xpoints[], int vertex[], double xmin, int attr,
               int npoints) {
      int i = 0;
      double EPS = 0.00001;

      while (i < npoints) {
          if (Math.abs(xpoints[i] - xmin) < EPS) {
            if ((vertex[i] == MAX && attr == MIN) ||
                (vertex[i] == MIN && attr == MAX)) {
                return false;
            }
          }
          if (xpoints[i] >= xmin) {
            for (int j = npoints-1; j >= i; j--) {
                xpoints[j+1] = xpoints[j];
                vertex[j+1] = vertex[j];
            }
            break;
          }
          i++;
      }

      xpoints[i] = xmin;
      vertex[i] = attr;
      
      return true;
    }
}
0
Comment
Question by:k1ngp1n99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
  • 3
  • +1
15 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 10652687
That'll be a classpath problem

set classpath=%classpath%;.

first (note dot at end)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10652691
0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 10652831
your code is an applet and not an application.
you need to define an html file with the *applet* tag and use a browser or and appletviewer to run it.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 10652842
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 10652979
LOL yes - it is an applet. Actually if you paste the following at the very top of your code (in the comments) you can run it from appletviewer *without* an html file

/*
<applet codebase="." code="Viewport.class" width="300" height="300">
</applet>
*/


How to run

C:\somedir>appletviewer Viewport.java
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10656179
0
 

Author Comment

by:k1ngp1n99
ID: 10656351
Thanks all. CEHJ i used you code in a new html file and the applet loaded perfectly.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10656365
I think maybe Grand should have got some points there too for picking up my mistake in not seeing that it was an applet...
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10656370
...but thanks 8-)
0
 

Author Comment

by:k1ngp1n99
ID: 10656427
sorry how do i give some point to grand. It was my mistake i should of split the points.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10656464
Post a zero-pointer to http://oldlook.experts-exchange.com:8080/Community_Support/
They'll reopen it
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10656486
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10656538
Well done - it's there
0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 10656926
thanks for the additional points k1ngp1n99
:°)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question