我想把一个正常类svm_predict转化为applet,转换后的代码如下(方法的具体内容略):class svm_predict extends Applet implements ActionListener
{
TextArea ta=new TextArea(50,100);
Button bn=new Button("ok");

public void init()
{
add(ta);
add(bn);
bn.addActionListener(this);
}

public void actionPerformed(ActionEvent e)
{
String argv[]={"test","svm.model","output"};
main(argv);
} private static void predict(BufferedReader input, DataOutputStream output, svm_model model, int predict_probability) throws IOException
{
...
} public static void main(String argv[]) throws IOException
{
          ...
}
}在编译时出现“未报告的异常 java.io.IOException;必须对其进行捕捉或声明以便抛出main(argv)”错误,请问这是怎么回事?怎么做能消除这个错误?
我对异常处理一窍不通,还请您用通俗一点的话解释一下。谢谢!

解决方案 »

  1.   

    你的哪几个方法 有IO 操作就把这个方法的后面加上throws IOException就可以了实在不行 看看你的代码
      

  2.   

    class svm_predict extends Applet implements ActionListener throws Exception
      

  3.   

    问题是我的main方法已经加上throws IOException啦,在actionPerformed方法里调用main的那个位置提示出错的
      

  4.   

    public void actionPerformed(ActionEvent e)
    {
    String argv[]={"test","svm.model","output"};
    try {
                      main(argv);
                       } catch(Exception ex) {
                       }
    }这样就可以了main方法抛出异常 你调用这个方法 肯定也要处理啊
      

  5.   

    回coolhorse:按你的方法加上以后再编译提示:需要 '{'
    class svm_predict extends Applet implements ActionListener throws Exception 
                                                              ^