我这里有一个没有main方法的类,在eclipse中可以运行,在APPLET窗口中显示图像
但是我在CMD下时是这样的:编译通过了,用java命令运行却告诉我
Exception in thread "main" java.lang.NoSuchMethodError: main为什么??

解决方案 »

  1.   


    在哪里都不能运行的,你要知道所有的java程序都是从main方法运行的,main方法就是程序的起点。
      

  2.   

    真的没有..我把源码发过来// 3D Mandelbrot mountains,  Evgeny Demidov  11 Oct 2001
    import java.awt.*;
    import java.awt.event.*;
    import java.util.StringTokenizer;public class Mandelbrot3D extends java.applet.Applet implements MouseListener,
    MouseMotionListener {
    int MaxIt = 300, n = 2, n1, h, w, h2, w2, mx0, my0, xPol[], yPol[]; double fiX = .2, fiY = .3, dfi = .01, scale = .8, m20, m21, m22, re0 = -2,
    im0 = -1.5, del = 3; double vert[][][], vert1[][][], Norm[][][][], Norm1z[][][]; Image buffImage; Graphics buffGraphics; Color[] col; boolean painted; public double Fun(double cr, double ci) {
    double I = 0.0, R = 0.0, I2 = 0.0, R2 = 0.0;
    int n = 0;
    do {
    I = R * (I + I) + ci;
    R = R2 - I2 + cr;
    R2 = R * R;
    I2 = I * I;
    n++;
    } while ((R2 + I2 < 4.0) && (n < MaxIt));
    return 40. * Math.log(n) - 100;
    } public void init() {
    w = getSize().width;
    h = getSize().height;
    w2 = w / 2;
    h2 = h / 2;
    String s = getParameter("N");
    if (s != null)
    n = Integer.parseInt(s);
    xPol = new int[3];
    yPol = new int[3];
    buffImage = createImage(w, h);
    buffGraphics = buffImage.getGraphics();
    col = new Color[256];
    for (int i = 0; i < 256; i++)
    col[i] = new Color(i, i, i);
    s = getParameter("coord");
    if (s != null) {
    StringTokenizer st = new StringTokenizer(s);
    re0 = Double.valueOf(st.nextToken()).doubleValue();
    im0 = Double.valueOf(st.nextToken()).doubleValue();
    del = Double.valueOf(st.nextToken()).doubleValue();
    }
    s = getParameter("bgColor");
    if (s != null) {
    StringTokenizer st = new StringTokenizer(s);
    int red = Integer.parseInt(st.nextToken());
    int green = Integer.parseInt(st.nextToken());
    int blue = Integer.parseInt(st.nextToken());
    setBackground(new Color(red, green, blue));
    } else
    setBackground(new Color(255, 255, 255));
    addMouseListener(this);
    addMouseMotionListener(this);
    setup();
    } public void setup() {
    n1 = n - 1;
    vert = new double[n][n][3];
    vert1 = new double[n][n][2];
    double n2 = n / 2., dx = w / (double) n1, dr = del / n1;
    for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
    vert[i][j][0] = dx * i - w2;
    vert[i][j][2] = dx * j - w2;
    vert[i][j][1] = Fun(re0 + dr * i, im0 + dr * j);
    }
    Norm = new double[n][n][2][3];
    Norm1z = new double[n][n][2];
    for (int i = 0; i < n1; i++)
    for (int j = 0; j < n1; j++) {
    Norm[i][j][0][0] = vert[i][j][1] - vert[i + 1][j][1];
    Norm[i][j][0][1] = dx;
    Norm[i][j][0][2] = vert[i + 1][j][1] - vert[i + 1][j + 1][1];
    double mod = Math.sqrt(Norm[i][j][0][0] * Norm[i][j][0][0]
    + Norm[i][j][0][1] * Norm[i][j][0][1]
    + Norm[i][j][0][2] * Norm[i][j][0][2]) / 255.5;
    Norm[i][j][0][0] /= mod;
    Norm[i][j][0][1] /= mod;
    Norm[i][j][0][2] /= mod;
    Norm[i][j][1][0] = vert[i][j + 1][1] - vert[i + 1][j + 1][1];
    Norm[i][j][1][1] = dx;
    Norm[i][j][1][2] = vert[i][j][1] - vert[i][j + 1][1];
    mod = Math.sqrt(Norm[i][j][1][0] * Norm[i][j][1][0]
    + Norm[i][j][1][1] * Norm[i][j][1][1]
    + Norm[i][j][1][2] * Norm[i][j][1][2]) / 255.5;
    Norm[i][j][1][0] /= mod;
    Norm[i][j][1][1] /= mod;
    Norm[i][j][1][2] /= mod;
    }
    rotate();
    } public void destroy() {
    removeMouseListener(this);
    removeMouseMotionListener(this);
    } public void mouseClicked(MouseEvent e) {
    } // event handling public void mousePressed(MouseEvent e) {
    mx0 = e.getX();
    my0 = e.getY();
    if (e.isControlDown()) {
    n /= 2;
    if (n < 4)
    n = 4;
    setup();
    repaint();
    }
    if (e.isAltDown()) {
    n *= 2;
    setup();
    repaint();
    }
    e.consume();
    } public void mouseReleased(MouseEvent e) {
    } public void mouseEntered(MouseEvent e) {
    } public void mouseExited(MouseEvent e) {
    } public void mouseDragged(MouseEvent e) {
    int x1 = e.getX();
    int y1 = e.getY();
    if (e.isShiftDown())
    scale *= Math.exp(-(y1 - my0) / (double) w);
    else
    fiX += dfi * (y1 - my0);
    fiY += dfi * (x1 - mx0);
    mx0 = x1;
    my0 = y1;
    rotate();
    repaint();
    e.consume();
    } public void rotate() {
    double ct = Math.cos(fiX), cf = Math.cos(fiY), st = Math.sin(fiX), sf = Math
    .sin(fiY), m00 = scale * cf, m02 = scale * sf, m10 = scale * st
    * sf, m11 = scale * ct, m12 = -scale * st * cf;
    m20 = -ct * sf;
    m21 = st;
    m22 = ct * cf;
    for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
    vert1[i][j][0] = m00 * vert[i][j][0] + m02 * vert[i][j][2];
    vert1[i][j][1] = m10 * vert[i][j][0] + m11 * vert[i][j][1]
    + m12 * vert[i][j][2];
    }
    for (int i = 0; i < n1; i++)
    for (int j = 0; j < n1; j++)
    for (int k = 0; k < 2; k++)
    Norm1z[i][j][k] = m20 * Norm[i][j][k][0] + m21
    * Norm[i][j][k][1] + m22 * Norm[i][j][k][2];
    painted = false;
    } public void mouseMoved(MouseEvent e) {
    } public void paint(Graphics g) {
    if (!painted) {
    buffGraphics.clearRect(0, 0, w, h);
    int ib = 0, ie = n1, sti = 1, jb = 0, je = n1, stj = 1;
    if (m20 < 0) {
    ib = n1;
    ie = -1;
    sti = -1;
    }
    if (m22 < 0) {
    jb = n1;
    je = -1;
    stj = -1;
    }
    for (int i = ib; i != ie; i += sti)
    for (int j = jb; j != je; j += stj) {
    if (Norm1z[i][j][0] > 0) {
    xPol[0] = w2 + (int) vert1[i][j][0];
    xPol[1] = w2 + (int) vert1[i + 1][j][0];
    xPol[2] = w2 + (int) vert1[i + 1][j + 1][0];
    yPol[0] = h2 - (int) vert1[i][j][1];
    yPol[1] = h2 - (int) vert1[i + 1][j][1];
    yPol[2] = h2 - (int) vert1[i + 1][j + 1][1];
    buffGraphics.setColor(col[(int) (Norm1z[i][j][0])]);
    buffGraphics.fillPolygon(xPol, yPol, 3);
    }
    if (Norm1z[i][j][1] > 0) {
    xPol[0] = w2 + (int) vert1[i][j][0];
    xPol[1] = w2 + (int) vert1[i][j + 1][0];
    xPol[2] = w2 + (int) vert1[i + 1][j + 1][0];
    yPol[0] = h2 - (int) vert1[i][j][1];
    yPol[1] = h2 - (int) vert1[i][j + 1][1];
    yPol[2] = h2 - (int) vert1[i + 1][j + 1][1];
    buffGraphics.setColor(col[(int) (Norm1z[i][j][1])]);
    buffGraphics.fillPolygon(xPol, yPol, 3);
    }
    }
    painted = true;
    }
    g.drawImage(buffImage, 0, 0, this);
    showStatus("n=" + n);
    } public void update(Graphics g) {
    paint(g);
    }}程序我还在读,但是在cmd遇到这个问题了,不知道为什么??
    这是分形数学
      

  3.   

    applet 不是java 运行的编译完生成class文件后这样:新建个html文件,右键-编辑,把class文件写在里面,然后保存 运行这个html<HTML>
    <TITLE>HelloWorld! Applet</TITLE>
    <APPLET
    CODE="JavaWorld.class"
    WIDTH=200
    HEIGHT=100>
    </APPLET>
    </HTML>
      

  4.   

    applet这个好像不是java运行的 好像是html
      

  5.   

    你把代码放在这里肯定不同了,那你说Servlet里面也没有main方法啊,那它怎么运行的呢?因为程序已经进入了运行,所以你嵌入的类没有main方法是可以运行的。
      

  6.   

    D:\fractal\分形java代码\第9章JAVA\9_03>javac Mandelbrot3D.javaD:\fractal\分形java代码\第9章JAVA\9_03>java Mandelbrot3D
    Exception in thread "main" java.lang.NoSuchMethodError: main
    我初学不多久,一开始不是说没个程序要有个main入口吗?
    这段也是java程序呀?!
      

  7.   

    哦!谢谢!
    java世界真强大,还好多要学
    呵呵
      

  8.   

    上面运行我说错了,应该是 appletviewer JavaWorld.html 
      

  9.   

    LZ
    你这是个applet 不需要main方法 要用html来调用
    先在CMD编译出class 再做个HTML文件来调用
    我说下步骤吧
    先把你的源码用CMD 的javac编译 
    编译出class后 在同一个文件夹中建一个HTML文件
    HTML文件代码如下
    <HTML>
    <TITLE>HelloWorld! Applet</TITLE>
    <APPLET
    CODE="Mandelbrot3D.class"
    WIDTH=500
    HEIGHT=500>
    </APPLET>
    </HTML>
    经过我试验可以运行~
      

  10.   

    为什么我试了一下浏览器打开的是这段代码HTML代码呢?
    <TITLE>HelloWorld! Applet </TITLE> 
    <APPLET 
    CODE="Mandelbrot3D.class" 
    WIDTH=500 
    HEIGHT=500> 
    </APPLET> 
    </HTML> 
      

  11.   

    我知道了!我复制的是全角格式的<>!