当前位置:编程学习 > JAVA >>

用Eclipse怎么运行JAVA程序

我想运行一个java程序其中commonSoundClass $Id: Queue.java,v 1.1 2001/05/04 21:22:05 mito Exp $package org.multichat;
import java.util.*;
public class CommonSoundClass {    public Vector vec = new Vector();    boolean lock = true;    private byte b[];

    public CommonSoundClass() {    }
    synchronized public Object readbyte() {        try {            while (vec.isEmpty()) {                wait();            }        }        catch (InterruptedException ie) {            System.err.println("Error: CommonSoundClass readbyte interrupted");        }
        if (! vec.isEmpty()) {            b = (byte[]) vec.remove(0);            return b;        } else {            byte[] b = new byte[5];            return b;        }
    }
    synchronized public void writebyte(Object e) {        vec.addElement(e);
        lock = false;        notifyAll();    }}结果我点击run,就出现
我应该怎么做?
追问:请问一下,具体怎么加入main函数? 能否把例图发给我
答案:添加main函数:
public static void main(String[] args)中的 (String[] args){
   //这里面生成类的实例就可以运行了
   CommonSoundClass  commonSoundClass = new CommonSoundClass ();
   //然后通过类的实例访问其中的方法,例如
   commonSoundClass .readbyte();
//其它的调用一样

先在你的java文件里面加入main函数,就可以run as java application

上一个:如何学好java ?
下一个:JAVA的学习心得

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,