2

我有一个非常奇怪的错误,使用 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);
            }

      }
4

1 回答 1

2

您的问题是由于试图将太多代码放入 Android 应用程序而引起的。根据这个问答 - Android:我的应用程序太大并给出“无法执行 dex:方法 ID 不在 [0, 0xffff]:65536”?- 解决方案是重构您的应用程序,以便某些代码采用插件的形式。

另一种方法是尝试消除死代码(即您的应用程序不需要的库类和方法)。此问答 - Android 错误“转换为 Dalvik 格式失败,错误 2”?- 建议使用 Proguard 来执行此操作。

于 2013-08-18T11:56:59.620 回答