错误:警告:无法从javaldx读取路径
警告:无法从javaldx读取路径错误:警告:无法从javaldx读取路径,java,exception,nullpointerexception,warnings,Java,Exception,Nullpointerexception,Warnings,警告:无法从javaldx读取路径 The Following Code is throwing the above warning: 上面的代码在开发机器上抛出警告,但它创建了正确的路径并最终正确地打开了文件。但是,在生产环境中,平台操作系统是Windows,它会在下面一行抛出空指针异常---> URL helpDocument=NewCellTrenderGUILauncher.class.getClass().getResource(“/G1-G2Help.doc”) 请帮助更正错
The Following Code is throwing the above warning:
上面的代码在开发机器上抛出警告,但它创建了正确的路径并最终正确地打开了文件。但是,在生产环境中,平台操作系统是Windows,它会在下面一行抛出空指针异常--->
URL helpDocument=NewCellTrenderGUILauncher.class.getClass().getResource(“/G1-G2Help.doc”)
请帮助更正错误。getResourceAsStream将轻松完成此任务。。试试看
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..!!");
}
}