The Following Code is throwing the above warning:   

Warning: failed to read path from javaldx

警告:无法从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..!!");
        }
    }

The above code throws warning on the development machine,but it creates the correct path and eventually opens the file correctly. But, in case of production environment, where the platform os is Windows, it throws a null pointer exception on the following line--->

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

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

Please help to rectify the error..

请帮忙纠正错误..

1 个解决方案

#1


0

The getResourceAsStream will do the job easily.. Try it

getResourceAsStream可以轻松完成工作..试试吧

更多相关文章

  1. 如何将树路径转换为json对象
  2. 填充java fx表时出现空指针异常
  3. Java - 获取ClassPath的路径和资源
  4. 在二叉树中找出和为某一值的所有路径-java实现
  5. Fragment中出现java.lang.NullPointerException 空指针 上下文为
  6. ArcGIS JS API For JavaScript实现类台风运动路径与影响范围的显
  7. 二维数组空指针异常
  8. 蓝桥杯--第七届决赛:路径之谜

随机推荐

  1. ListView使用技巧
  2. Android SharedPreferences和File
  3. android中SharedPreferences和Preference
  4. ANDROID模拟器不能启动
  5. android实现开机欢迎界面
  6. 【学习笔记】android基本环境
  7. android线程调度工具类SchedulerUtils
  8. Andriod(3)——Understanding Android(安
  9. Android实现系统重新启动
  10. Android常用的技术点