java core  的示例代码,
try
{
MaskFormatter formatter = new MaskFormatter("###-##-####");
formatter.setPlaceholderCharacter('0');
JFormattedTextField ssnField = new JFormattedTextField(formatter);
ssnField.setValue("078-05-1120");
addRow("SSN Mask:",ssnField);
}
catch (ParseException exception)
{
exception.printStackTrace();
}
可是编译器就是说MaskFormatter(String)的抛出异常没有捕获,怎么搞得??online 等待,有解,立结

解决方案 »

  1.   

    catch   (Exception   exception) // 修改一下
      

  2.   

    我看了一下,你是不是逻辑有问题呀?比如{}有没有对齐什么的,我在机子上试了,没有你说的问题的.要不你再改ParseException为Exception试一下,再不对,就是你的逻辑有问题了,你看看你整个代码的逻辑吧!
      

  3.   

    正解!
    虽然 http://gceclub.sun.com.cn/Java_Docs/jdk6/html/zh_CN/api/index.html
    说 public MaskFormatter(String mask)
                  throws ParseException但似乎抛出的并不是一个 ParseException,
    看来sun的帮助文档有问题啊。
      

  4.   

    正解!
    虽然 http://gceclub.sun.com.cn/Java_Docs/jdk6/html/zh_CN/api/index.html
    说 public MaskFormatter(String mask)
                  throws ParseException但似乎抛出的并不是一个 ParseException,
    看来sun的帮助文档有问题啊。
      

  5.   

    嗯,这个是有可能的.不过你看的是jdk1.6的文档,你用的编译器的jdk也是1.6吗?