0
The Following Code is throwing the above warning:   

警告:无法从 javaldx 读取路径

if((JButton)e.getSource()==helpButton)
    {
        System.out.println("-------------Help Button is pressed..----------------------");
        URL helpDocument=NewCellTrenderGUILauncher.class.getClass().getResource("/G1-G2Help.doc");
        System.out.println("URL Constructed-->"+helpDocument.toString());

        File helpDocPath=null;
        try
        {
            System.out.println("URI constructed from URL="+helpDocument.toURI());
            helpDocPath = new File(helpDocument.toURI());
            System.out.println("File Path Constructed from URI="+helpDocPath.toString());
        } catch (URISyntaxException e2)
        {
            // TODO Auto-generated catch block
            System.err.println("\n\t***********************EXCEPTION*****************");
            System.err.println("\tDue to--->"+e2);
            System.err.println("\tExceptionType--->"+e2.getMessage());
            e2.printStackTrace();
            System.err.println("\t**************************************************");
        }

        if(Desktop.isDesktopSupported())
        {
            System.out.println("DesktopSupported is TRUE..!!");
            try
            {
                Desktop.getDesktop().open(helpDocPath);
                System.out.println("FileOpened From Desktop..!!");
            } catch (IOException e1)
            {
                // TODO Auto-generated catch block
                System.err.println("\n\t***********************EXCEPTION*****************");
                System.err.println("\tDue to--->"+e1);
                System.err.println("\tExceptionType--->"+e1.getMessage());
                e1.printStackTrace();
                System.err.println("\t**************************************************");
                FileRenderer.openFile(helpDocPath.toString());
                System.out.println("File opened from FileReneder..!!");
            }
        }
        else
        {
            System.out.println("Desptop is Not Supported..!!!");
            FileRenderer.openFile(helpDocPath.toString());
            System.out.println("File opened from FileReneder..!!");
        }
    }

上面的代码在开发机器上抛出警告,但它创建了正确的路径并最终正确打开了文件。但是,在平台操作系统为 Windows 的生产环境中,它会在以下行引发空指针异常--->

URL helpDocument=NewCellTrenderGUILauncher.class.getClass().getResource("/G1-G2Help.doc");

请帮助纠正错误..

4

1 回答 1

0

getResourceAsStream 将轻松完成这项工作.. 试试看

于 2012-12-27T13:48:37.280 回答