所以我得到了这个Excel文件,我想从中读取一些数据,我发现Apache POI api似乎做了我想要的。我虽然得到了一些轻微的追赶。我的Gradle Sync似乎很好,但每当我尝试运行应用程序时,都会收到以下错误消息:
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
AGPBI: {"kind":"error","text":"trouble processing \"javax/xml/XMLConstants.class\":","sources":[{}]}
AGPBI: {"kind":"error","text":"Ill-advised or mistaken usage of a core class (java.* or javax.*)","sources":[{}]}
AGPBI: {"kind":"error","text":"when not building a core library.","sources":[{}]}
AGPBI: {"kind":"error","text":"This is often due to inadvertently including a core library file","sources":[{}]}
AGPBI: {"kind":"error","text":"in your application\u0027s project, when using an IDE (such as","sources":[{}]}
AGPBI: {"kind":"error","text":"Eclipse). If you are sure you\u0027re not intentionally defining a","sources":[{}]}
AGPBI: {"kind":"error","text":"core class, then this is the most likely explanation of what\u0027s","sources":[{}]}
AGPBI: {"kind":"error","text":"going on.","sources":[{}]}
AGPBI: {"kind":"error","text":"However, you might actually be trying to define a class in a core","sources":[{}]}
AGPBI: {"kind":"error","text":"namespace, the source of which you may have taken, for example,","sources":[{}]}
AGPBI: {"kind":"error","text":"from a non-Android virtual machine project. This will most","sources":[{}]}
AGPBI: {"kind":"error","text":"assuredly not work. At a minimum, it jeopardizes the","sources":[{}]}
AGPBI: {"kind":"error","text":"compatibility of your app with future versions of the platform.","sources":[{}]}
AGPBI: {"kind":"error","text":"It is also often of questionable legality.","sources":[{}]}
AGPBI: {"kind":"error","text":"If you really intend to build a core library -- which is only","sources":[{}]}
AGPBI: {"kind":"error","text":"appropriate as part of creating a full virtual machine","sources":[{}]}
AGPBI: {"kind":"error","text":"distribution, as opposed to compiling an application -- then use","sources":[{}]}
AGPBI: {"kind":"error","text":"the \"--core-library\" option to suppress this error message.","sources":[{}]}
AGPBI: {"kind":"error","text":"If you go ahead and use \"--core-library\" but are in fact","sources":[{}]}
AGPBI: {"kind":"error","text":"building an application, then be forewarned that your application","sources":[{}]}
AGPBI: {"kind":"error","text":"will still fail to build or run, at some point. Please be","sources":[{}]}
AGPBI: {"kind":"error","text":"prepared for angry customers who find, for example, that your","sources":[{}]}
AGPBI: {"kind":"error","text":"application ceases to function once they upgrade their operating","sources":[{}]}
AGPBI: {"kind":"error","text":"system. You will be to blame for this problem.","sources":[{}]}
AGPBI: {"kind":"error","text":"If you are legitimately using some code that happens to be in a","sources":[{}]}
AGPBI: {"kind":"error","text":"core package, then the easiest safe alternative you have is to","sources":[{}]}
AGPBI: {"kind":"error","text":"repackage that code. That is, move the classes in question into","sources":[{}]}
AGPBI: {"kind":"error","text":"your own package namespace. This means that they will never be in","sources":[{}]}
AGPBI: {"kind":"error","text":"conflict with core system classes. JarJar is a tool that may help","sources":[{}]}
AGPBI: {"kind":"error","text":"you in this endeavor. If you find that you cannot do this, then","sources":[{}]}
AGPBI: {"kind":"error","text":"that is an indication that the path you are on will ultimately","sources":[{}]}
AGPBI: {"kind":"error","text":"lead to pain, suffering, grief, and lamentation.","sources":[{}]}
AGPBI: {"kind":"error","text":"1 error; aborting","sources":[{}]}
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException:
Error:trouble processing "javax/xml/XMLConstants.class":
Error:Ill-advised or mistaken usage of a core class (java.* or javax.*)
Error:when not building a core library.
Error:This is often due to inadvertently including a core library file
Error:in your application's project, when using an IDE (such as
Error:Eclipse). If you are sure you're not intentionally defining a
Error:core class, then this is the most likely explanation of what's
Error:going on.
Error:However, you might actually be trying to define a class in a core
Error:namespace, the source of which you may have taken, for example,
Error:from a non-Android virtual machine project. This will most
Error:assuredly not work. At a minimum, it jeopardizes the
Error:compatibility of your app with future versions of the platform.
Error:It is also often of questionable legality.
Error:If you really intend to build a core library -- which is only
Error:appropriate as part of creating a full virtual machine
Error:distribution, as opposed to compiling an application -- then use
Error:the "--core-library" option to suppress this error message.
Error:If you go ahead and use "--core-library" but are in fact
Error:building an application, then be forewarned that your application
Error:will still fail to build or run, at some point. Please be
Error:prepared for angry customers who find, for example, that your
Error:application ceases to function once they upgrade their operating
Error:system. You will be to blame for this problem.
Error:If you are legitimately using some code that happens to be in a
Error:core package, then the easiest safe alternative you have is to
Error:repackage that code. That is, move the classes in question into
Error:your own package namespace. This means that they will never be in
Error:conflict with core system classes. JarJar is a tool that may help
Error:you in this endeavor. If you find that you cannot do this, then
Error:that is an indication that the path you are on will ultimately
Error:lead to pain, suffering, grief, and lamentation.
Error:1 error; aborting
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_51\bin\java.exe'' finished with non-zero exit value 1

我尝试了两种方法来添加依赖项。首先,我从他们的网站下载了所有jar文件。将它们放在libs文件夹中,并在gradle文件中添加文件树依赖项。这没有用。现在我只是用它来代替:
compile 'org.apache.poi:poi:3.14'
compile 'org.apache.poi:poi-ooxml:3.14'
compile 'org.apache.poi:poi-ooxml-schemas:3.14'
compile 'org.apache.xmlbeans:xmlbeans:2.6.0'
compile 'com.github.virtuald:curvesapi:1.03'
//这是实际代码:
private void XLSFileReader(){
try {
FileInputStream file = new FileInputStream(new File(xlsFilePath));
//Create Workbook instance holding reference to .xlsx file
XSSFWorkbook workbook = new XSSFWorkbook(file);
//Get first/desired sheet from the workbook
XSSFSheet sheet = workbook.getSheetAt(0);
//Iterate through each rows one by one
Iterator<Row> rowIterator = sheet.iterator();
while (rowIterator.hasNext())
{
Row row = rowIterator.next();
//For each row, iterate through all the columns
Iterator<Cell> cellIterator = row.cellIterator();
while (cellIterator.hasNext())
{
Cell cell = cellIterator.next();
//Check the cell type and format accordingly
switch (cell.getCellType())
{
//Logs to the window to confirm that it works
case Cell.CELL_TYPE_NUMERIC:
Log.d("Kolumn", cell.getNumericCellValue() + "\t");
break;
case Cell.CELL_TYPE_STRING:
Log.d("Rad",cell.getStringCellValue() + "\t");
break;
}
}
System.out.println("");
}
file.close();
} catch (Exception e) {
e.printStackTrace();
}
我搜索了很多,但我找到的方法都没有为我工作。
答案 0 :(得分:1)
阅读这篇文章 - http://blog.kondratev.pro/2015/08/reading-xlsx-on-android-4-and-hopefully.html问题出在xmlbeans-2.6.0.jar