【问题标题】:trouble writing output: Too many methods: 66024; max is 65536. By package: ERROR [duplicate]编写输出时遇到问题:方法太多:66024;最大值为 65536。按包:错误 [重复]
【发布时间】:2013-08-18 09:45:56
【问题描述】:

我有一个非常奇怪的错误,使用 apache poi,我认为它与 ooxml-schemas--.jar 文件有关。我基本上是在尝试将 xlsx 文件读入内部存储,但它没有发生。

详细信息:我正在使用 Apache Poi 3.9 从 android 中的 res.raw 文件夹中读取它是一个 xlsx 文件,它使用 Outputstream 将自己应对到 android 中的内部存储。它只是没有发生。这是错误日志:

trouble writing output: Too many methods: 66024; max is 65536. By package:
    13 java.lang
     1 java.lang.reflect
     5 java.util
     1 javax.xml.namespace
    66 org.apache.xmlbeans
    19 org.apache.xmlbeans.impl.values
     1 org.apache.xmlbeans.impl.xb.xmlschema
  2500 org.openxmlformats.schemas.drawingml.x2006.chart
  1430 org.openxmlformats.schemas.drawingml.x2006.chart.impl
  8767 org.openxmlformats.schemas.drawingml.x2006.main
  5258 org.openxmlformats.schemas.drawingml.x2006.main.impl
    86 org.openxmlformats.schemas.drawingml.x2006.picture
    33 org.openxmlformats.schemas.drawingml.x2006.picture.impl
   745 org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing
   417 org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.impl
   230 org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing
   164 org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.impl
   298 org.openxmlformats.schemas.officeDocument.x2006.customProperties
   256 org.openxmlformats.schemas.officeDocument.x2006.customProperties.impl
   617 org.openxmlformats.schemas.officeDocument.x2006.docPropsVTypes
   596 org.openxmlformats.schemas.officeDocument.x2006.docPropsVTypes.impl
   285 org.openxmlformats.schemas.officeDocument.x2006.extendedProperties
   196 org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.impl
    23 org.openxmlformats.schemas.officeDocument.x2006.math
    24 org.openxmlformats.schemas.officeDocument.x2006.relationships
     2 org.openxmlformats.schemas.officeDocument.x2006.relationships.impl
  2076 org.openxmlformats.schemas.presentationml.x2006.main
  1224 org.openxmlformats.schemas.presentationml.x2006.main.impl
     1 org.openxmlformats.schemas.schemaLibrary.x2006.main
  7271 org.openxmlformats.schemas.spreadsheetml.x2006.main
  4556 org.openxmlformats.schemas.spreadsheetml.x2006.main.impl
 11448 org.openxmlformats.schemas.wordprocessingml.x2006.main
  9217 org.openxmlformats.schemas.wordprocessingml.x2006.main.impl
     4 schemaorg_apache_xmlbeans.system.sE130CAA0A01A7CDE5A2B4FEB8B311707
  1170 schemasMicrosoftComOfficeExcel
  1223 schemasMicrosoftComOfficeExcel.impl
   285 schemasMicrosoftComOfficeOffice
   124 schemasMicrosoftComOfficeOffice.impl
     2 schemasMicrosoftComOfficePowerpoint
     3 schemasMicrosoftComOfficeWord
  2858 schemasMicrosoftComVml
  2529 schemasMicrosoftComVml.impl
[2013-08-18 14:21:31 - gss4] Conversion to Dalvik format failed with error 2

到底发生了什么?

这是我正在使用的功能:

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        readAndWrite();

    }


    public void readAndWrite() {
          try
            {
              // Read from original Excel file. //Get from RawResources in Android
              InputStream inputStream = getResources().openRawResource(R.raw.ems_data);
              OutputStream fos = openFileOutput("ems_data.xlsx", Context.MODE_PRIVATE);
              Workbook workbook = WorkbookFactory.create(inputStream );

              // Get the first sheet.
              Sheet sheet = workbook.getSheetAt(0);

              // Set value of the first cell.
              Row row = sheet.getRow(0);
              Cell cell = row.getCell(0);
              cell.setCellValue("Xuan");

              // Write newly modified workbook to a file. //Copy to Internal Storage in Android
            //  FileOutputStream fileOut = new FileOutputStream("/sdcard/ems_data3new.xlsx");
              workbook.write(fos);
              fos.close();
            }
            catch(FileNotFoundException e)
            {
              System.out.println(e);
            }
            catch(IOException e)
            {
              System.out.println(e);
            }
            catch(InvalidFormatException e)
            {
              System.out.println(e);
            }

      }

【问题讨论】:

  • 我建议您阅读有关同一错误消息的其他问题。
  • 我有。他们都没有谈论如何解决这个问题。 this 是谷歌工程师的演讲,对我来说有点太高级了。
  • 好吧,我找不到任何东西来解决这个问题...
  • @AhmedZafar - 从输出中可以清楚地看出,您没有按照您所说的去做。输出显然与将某些内容转换为 Davlik 格式有关。请清楚准确地说明您实际在做什么,以及您是如何做的......
  • @StephenC- 我已经修改了问题以适合我正在使用的代码。是的,我认为 dalvik 转换搞砸了,因为该函数在 java 中工作(尽管显然它没有从原始文件中检索文件或将其写入内部文件,而是在硬盘上执行此操作)。我已经写了我正在做的事情,它返回了太多的方法。我不明白你为什么说我没有说我在做什么!

标签: java android eclipse apache-poi dalvik


【解决方案1】:

您的问题是由于尝试将过多代码放入 Android 应用而引起的。根据这个问答 - Android: my application is too large and gives "Unable to execute dex: method ID not in [0, 0xffff]: 65536"? - 解决方案是重构您的应用程序,以便某些代码采用插件的形式。

另一种方法是尝试消除死代码(即您的应用不需要的库类和方法)。此问答 - Android Error "Conversion to Dalvik format failed with error 2"? - 建议使用 Proguard 来执行此操作。

【讨论】:

  • 我现在的整个代码就是一个函数。其余的只是 libs 文件夹中的 jar 文件。我该怎么处理他们?
  • 阅读链接的问题。
  • 谢谢。我已经阅读了它们,我得出的唯一结论是从我的库中删除一些库。但我不能这样做,因为我需要它们。我也无法“拆分” dex 文件,因为我不知道如何...
  • 您说得对,先生。这里有一些关于这个问题的好读物。 Apache 可以在 Android 上很好地处理 HSSF(xls),但在处理 XSSF (xlsx) 时会产生太多方法。这是一个遗憾。一个土豆给你! :) http://mail-archives.apache.org/mod_mbox/poi-dev/201110.mbox/%3CCA+JOeWNWinmNmEtHs5VK+KEc_6BzAG_=LfpdXqsDsnjJKR2X7Q@mail.gmail.com%3E
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-12-31
  • 1970-01-01
  • 1970-01-01
  • 2018-12-21
  • 1970-01-01
  • 2017-11-20
  • 1970-01-01
相关资源
最近更新 更多