none
用LocalReport打印报表时报空指针异常 RRS feed

  • 问题

  • 我LocalReport实现不预览直接打印报表时出现空指针异常,异常报得非常奇怪。程序平时运行很正常,偶尔重启机器后第一次就报异常。报异常后把程序退了重新运行就能正常工作。下面是我的代码,可以确定我的传值不会存在空指针,想请问下一有谁遇到过,怎么处理的。。

    private Stream CreateStream(string name, string fileNameExtension, Encoding encoding, string mimeType, bool willSeek)
            {
                try
                {
                    return createStream(name, fileNameExtension);
                }
                catch (Exception ex)
                {
                    PublicMethods.WriteSystemLog.WriteLogFromPrint(ex, "创建Stream时出错");
                    return null;
                }
            }
    
            private bool Export(LocalReport report)
            {
                bool flag = true;
                try
                {
                    string deviceInfo =
                    "<DeviceInfo>" +
                    "  <OutputFormat>EMF</OutputFormat>" +
                    "  <PageWidth>76mm</PageWidth>" +
                    "  <PageHeight>297mm</PageHeight>" +
                    "  <MarginTop>0mm</MarginTop>" +
                    "  <MarginLeft>0mm</MarginLeft>" +
                    "  <MarginRight>0mm</MarginRight>" +
                    "  <MarginBottom>0mm</MarginBottom>" +
                    "</DeviceInfo>";
    
                    Warning[] warnings;
                    m_streams = new List<Stream>();
                    try
                    {
                        report.Render("Image", deviceInfo, CreateStream, out warnings);//问题出在这句
                    }
                    catch (Exception ex)
                    {
                        flag = false;
                        PublicMethods.WriteSystemLog.WriteLogFromPrint(ex, "呈现报表时出错");
                    }
    
                    foreach (Stream stream in m_streams)
                    {
                        stream.Position = 0;
                    }
                }
                catch (Exception ex)
                {
                    flag = false;
                }
                return flag;
            }



    小鸡快跑

    2013年1月7日 4:29

全部回复