Caused by: java.lang.NullPointerException: charsetName?

B_qxzb 2013-06-19 01:56:06
1.出错日志

Caused by: java.lang.NullPointerException: charsetName
at java.lang.String.(String.java:403)
at jxl.biff.StringHelper.getString(StringHelper.java:164)
at jxl.biff.FormatRecord.(FormatRecord.java:161)
at jxl.read.biff.WorkbookParser.parse(WorkbookParser.java:638)
at jxl.Workbook.getWorkbook(Workbook.java:237)
at jxl.Workbook.getWorkbook(Workbook.java:198)
at com.ppet.inv.BalanceUpdateAction.execute(BalanceUpdateAction.java:106)
... 36 more


2. BalanceUpdateAction.execute:代码截图




----------------------
这个是excel更新库存时的出错信息……
请问,出现这个错误的原因可能是什么呢?
...全文
280 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
B_qxzb 2013-06-19
  • 打赏
  • 举报
回复
谢谢,我再好好想下!
引用 2 楼 beichui 的回复:
另外,JXL的配置里面你是否把encoding配置错误了,上面贴的第一段构造方法的代码中,encoding的设置还会被你的JXL配置覆盖掉。

    // Initialize the locale to the system locale
    try
    {
      if (System.getProperty("jxl.lang")    == null ||
          System.getProperty("jxl.country") == null)
      {
        locale = Locale.getDefault();
      }
      else
      {
        locale = new Locale(System.getProperty("jxl.lang"),
                            System.getProperty("jxl.country"));
      }

      if (System.getProperty("jxl.encoding") != null)
      {
        //这里覆盖
        encoding = System.getProperty("jxl.encoding");
      }
    } 
    catch (SecurityException e)
    {
      logger.warn("Error accessing system properties.", e);
      locale = Locale.getDefault();
    }
北吹 2013-06-19
  • 打赏
  • 举报
回复
另外,JXL的配置里面你是否把encoding配置错误了,上面贴的第一段构造方法的代码中,encoding的设置还会被你的JXL配置覆盖掉。

    // Initialize the locale to the system locale
    try
    {
      if (System.getProperty("jxl.lang")    == null ||
          System.getProperty("jxl.country") == null)
      {
        locale = Locale.getDefault();
      }
      else
      {
        locale = new Locale(System.getProperty("jxl.lang"),
                            System.getProperty("jxl.country"));
      }

      if (System.getProperty("jxl.encoding") != null)
      {
        //这里覆盖
        encoding = System.getProperty("jxl.encoding");
      }
    } 
    catch (SecurityException e)
    {
      logger.warn("Error accessing system properties.", e);
      locale = Locale.getDefault();
    }
北吹 2013-06-19
  • 打赏
  • 举报
回复
查看了下源码,getWorkbook(File) 会创建一个默认的WorkbookSettings 对象,这个设置对象默认的encoding是由 System.getProperty("file.encoding")获得的。

  public WorkbookSettings()
  {
    initialFileSize = DEFAULT_INITIAL_FILE_SIZE;
    arrayGrowSize = DEFAULT_ARRAY_GROW_SIZE;
    localeFunctionNames = new HashMap();
    excelDisplayLanguage = CountryCode.USA.getCode();
    excelRegionalSettings = CountryCode.UK.getCode();
    refreshAll = false;
    template = false;
    excel9file = false;
    windowProtected = false;
    hideobj = HIDEOBJ_SHOW_ALL;

    // Initialize other properties from the system properties
    try
    {
      boolean suppressWarnings = Boolean.getBoolean("jxl.nowarnings");
      setSuppressWarnings(suppressWarnings);
      drawingsDisabled        = Boolean.getBoolean("jxl.nodrawings");
      namesDisabled           = Boolean.getBoolean("jxl.nonames");
      gcDisabled              = Boolean.getBoolean("jxl.nogc");
      rationalizationDisabled = Boolean.getBoolean("jxl.norat");
      mergedCellCheckingDisabled =
        Boolean.getBoolean("jxl.nomergedcellchecks");
      formulaReferenceAdjustDisabled =
                                Boolean.getBoolean("jxl.noformulaadjust");
      propertySetsDisabled = Boolean.getBoolean("jxl.nopropertysets");
      ignoreBlankCells = Boolean.getBoolean("jxl.ignoreblanks");
      cellValidationDisabled = Boolean.getBoolean("jxl.nocellvalidation");
      autoFilterDisabled = !Boolean.getBoolean("jxl.autofilter"); 
             // autofilter currently disabled by default
      useTemporaryFileDuringWrite = 
        Boolean.getBoolean("jxl.usetemporaryfileduringwrite");
      String tempdir =
        System.getProperty("jxl.temporaryfileduringwritedirectory");

      if (tempdir != null)
      {
        temporaryFileDuringWriteDirectory = new File(tempdir);
      }
      //在这里设置的
      encoding = System.getProperty("file.encoding");
    }
    catch (SecurityException e)
    {
      logger.warn("Error accessing system properties.", e);
    }

    // Initialize the locale to the system locale
    try
    {
      if (System.getProperty("jxl.lang")    == null ||
          System.getProperty("jxl.country") == null)
      {
        locale = Locale.getDefault();
      }
      else
      {
        locale = new Locale(System.getProperty("jxl.lang"),
                            System.getProperty("jxl.country"));
      }

      if (System.getProperty("jxl.encoding") != null)
      {
        encoding = System.getProperty("jxl.encoding");
      }
    } 
    catch (SecurityException e)
    {
      logger.warn("Error accessing system properties.", e);
      locale = Locale.getDefault();
    }
  }
StringHelper使用的就是这个encoding:

  public static String getString(byte[] d, int length, int pos,
                                 WorkbookSettings ws)
  {
    if( length == 0 )
    {
      return "";  // Reduces number of new Strings
    }

    try
    {
      return new String(d, pos, length, ws.getEncoding());
      //      byte[] b = new byte[length];
      //      System.arraycopy(d, pos, b, 0, length);
      //      return new String(b, ws.getEncoding());
    }
    catch (UnsupportedEncodingException e)
    {
      logger.warn(e.toString());
      return "";
    }
  }
查看下System.getProperty("file.encoding")获得的系统编码是否正确。

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧