2015-10-18 121 views
2

剛開始,我並不想從Android中的.xlsx文件讀取單元格, 我已經嘗試了幾乎所有我Google搜索的內容,但每次(java.exe完成非零退出值1

Error:Execution failed for task ':app:dexDebug'. 
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_79\bin\java.exe'' finished with non-zero exit value 1 

我不知道,還有什麼我應該做的,Java和:在兩個不同的PC,包括Java 1.7.0_79)當我試圖建立(運行)這個應用程序,它與同樣的錯誤結束Android Studio已重新安裝...沒有。我用代碼從https://github.com/hmkcode/Java/tree/master/java-excel-poi

消息

Information:Gradle tasks [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:assembleDebug] 
:app:preBuild UP-TO-DATE 
:app:preDebugBuild UP-TO-DATE 
:app:checkDebugManifest 
:app:preReleaseBuild UP-TO-DATE 
:app:prepareComAndroidSupportAppcompatV72310Library UP-TO-DATE 
:app:prepareComAndroidSupportMultidex100Library UP-TO-DATE 
:app:prepareComAndroidSupportSupportV42310Library UP-TO-DATE 
:app:prepareDebugDependencies 
:app:compileDebugAidl UP-TO-DATE 
:app:compileDebugRenderscript UP-TO-DATE 
:app:generateDebugBuildConfig UP-TO-DATE 
:app:generateDebugAssets UP-TO-DATE 
:app:mergeDebugAssets UP-TO-DATE 
:app:generateDebugResValues UP-TO-DATE 
:app:generateDebugResources UP-TO-DATE 
:app:mergeDebugResources UP-TO-DATE 
:app:processDebugManifest UP-TO-DATE 
:app:processDebugResources UP-TO-DATE 
:app:generateDebugSources UP-TO-DATE 
:app:preDebugAndroidTestBuild UP-TO-DATE 
:app:prepareDebugAndroidTestDependencies 
:app:compileDebugAndroidTestAidl UP-TO-DATE 
:app:processDebugAndroidTestManifest UP-TO-DATE 
:app:compileDebugAndroidTestRenderscript UP-TO-DATE 
:app:generateDebugAndroidTestBuildConfig UP-TO-DATE 
:app:generateDebugAndroidTestAssets UP-TO-DATE 
:app:mergeDebugAndroidTestAssets UP-TO-DATE 
:app:generateDebugAndroidTestResValues UP-TO-DATE 
:app:generateDebugAndroidTestResources UP-TO-DATE 
:app:mergeDebugAndroidTestResources UP-TO-DATE 
:app:processDebugAndroidTestResources UP-TO-DATE 
:app:generateDebugAndroidTestSources UP-TO-DATE 
:app:processDebugJavaRes UP-TO-DATE 
:app:compileDebugJavaWithJavac UP-TO-DATE 
:app:compileDebugNdk UP-TO-DATE 
:app:compileDebugSources UP-TO-DATE 
:app:dexDebug 
trouble processing "javax/xml/stream/events/StartElement.class": 
Ill-advised or mistaken usage of a core class (java.* or javax.*) 
when not building a core library. 
This is often due to inadvertently including a core library file 
in your application's project, when using an IDE (such as 
Eclipse). If you are sure you're not intentionally defining a 
core class, then this is the most likely explanation of what's 
going on. 
However, you might actually be trying to define a class in a core 
namespace, the source of which you may have taken, for example, 
from a non-Android virtual machine project. This will most 
assuredly not work. At a minimum, it jeopardizes the 
compatibility of your app with future versions of the platform. 
It is also often of questionable legality. 
If you really intend to build a core library -- which is only 
appropriate as part of creating a full virtual machine 
distribution, as opposed to compiling an application -- then use 
the "--core-library" option to suppress this error message. 
If you go ahead and use "--core-library" but are in fact 
building an application, then be forewarned that your application 
will still fail to build or run, at some point. Please be 
prepared for angry customers who find, for example, that your 
application ceases to function once they upgrade their operating 
system. You will be to blame for this problem. 
If you are legitimately using some code that happens to be in a 
core package, then the easiest safe alternative you have is to 
repackage that code. That is, move the classes in question into 
your own package namespace. This means that they will never be in 
conflict with core system classes. JarJar is a tool that may help 
you in this endeavor. If you find that you cannot do this, then 
that is an indication that the path you are on will ultimately 
lead to pain, suffering, grief, and lamentation. 
1 error; aborting 
Error:Execution failed for task ':app:dexDebug'. 
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_79\bin\java.exe'' finished with non-zero exit value 1 
Information:BUILD FAILED 
Information:Total time: 2.301 secs 
Information:1 error 
Information:0 warnings 
Information:See complete output in console 

MainActivity.java完整輸出

package tona_kriz.kriziksupl; 

import android.app.Activity; 
import android.content.res.AssetManager; 
import android.os.Bundle; 
import android.widget.Toast; 

import java.io.BufferedInputStream; 
import java.io.FileNotFoundException; 
import java.io.IOException; 
import java.io.InputStream; 
import java.util.Date; 

import org.apache.poi.ss.usermodel.Cell; 
import org.apache.poi.ss.usermodel.Sheet; 
import org.apache.poi.ss.usermodel.Workbook; 
import org.apache.poi.xssf.usermodel.XSSFWorkbook; 

public class MainActivity extends Activity { 


    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     Workbook wb = null; 

     //1. Open the file 

     try { 
      AssetManager assManager = getApplicationContext().getAssets(); 
      InputStream is = null; 
      try { 
       is = assManager.open("supl_zak.xlsx"); 
      } catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
      InputStream caInput = new BufferedInputStream(is); 
      wb = new XSSFWorkbook(caInput); 
      int i = wb.getNumberOfSheets(); 
      Toast.makeText(getApplicationContext(), "pocet: " + i, Toast.LENGTH_SHORT).show(); 
      Toast.makeText(getApplicationContext(), "otevreno", Toast.LENGTH_SHORT).show(); 
     } catch (FileNotFoundException e) { 
      e.printStackTrace(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 

     //2. Open a sheet 
     Sheet sheet = wb.getSheetAt(0); 


     //3. Get each cell by row & column number 
     Cell cell; 
     //Cell cell = sheet.getRow(0).getCell(0); 
     //double numberVal = cell.getNumericCellValue(); 
     //System.out.println("Row: 0 - Column: 0 = "+numberVal); 
     //----------------------------- 
     cell = sheet.getRow(0).getCell(8); 
     String stringVal = cell.getStringCellValue(); 
     System.out.println("Row: 0 - Column: 1 = "+stringVal); 
     //----------------------------- 
     //cell = sheet.getRow(0).getCell(2); 
     //Date dateVal = cell.getDateCellValue(); 
     //System.out.println("Row: 0 - Column: 2 = "+dateVal); 
     //----------------------------- 
     //cell = sheet.getRow(0).getCell(3); 
     //boolean booleanVal = cell.getBooleanCellValue(); 
     //System.out.println("Row: 0 - Column: 3 = "+booleanVal); 
     //----------------------------- 

    } 
} 

的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="tona_kriz.kriziksupl" > 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:largeHeap="true" 
     android:theme="@style/AppTheme" 
     android:name="android.support.multidex.MultiDexApplication"> > 
     <activity android:name=".MainActivity" > 
      <intent-filter> 

       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application> 

</manifest> 

的build.gradle

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.1" 

    compileOptions { 
     sourceCompatibility JavaVersion.VERSION_1_7 
     targetCompatibility JavaVersion.VERSION_1_7 
    } 

    dexOptions { 
     preDexLibraries false 
     incremental true 
     javaMaxHeapSize "4g" 
    } 

    afterEvaluate { 
     tasks.matching { 
      it.name.startsWith('dex') 
     }.each { dx -> 
      if (dx.additionalParameters == null) { 
       dx.additionalParameters = ['--multi-dex'] 
      } else { 
       dx.additionalParameters += '--multi-dex' 
      } 
     } 
    } 

    packagingOptions { 
     exclude 'META-INF/LICENSE' 
     exclude 'META-INF/NOTICE' 
     exclude 'META-INF/LICENSE' 
     exclude 'META-INF/NOTICE' 
    } 

    defaultConfig { 
     applicationId "tona_kriz.kriziksupl" 
     minSdkVersion 16 
     targetSdkVersion 23 
     versionCode 1 
     versionName "1.0" 

     multiDexEnabled false 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile 'com.android.support:appcompat-v7:23.1.0' 
    compile 'com.android.support:multidex:1.0.0' 
    compile files('libs/commons-codec-1.5.jar') 
    compile files('libs/dom4j-1.6.1.jar') 
    compile files('libs/poi-3.9.jar') 
    compile files('libs/poi-ooxml-3.9.jar') 
    compile files('libs/poi-ooxml-schemas-3.9.jar') 
    compile files('libs/stax-api-1.0.1.jar') 
    compile files('libs/xml-apis-1.0.b2.jar') 
    compile files('libs/xmlbeans.jar') 
} 

,當我刪除:

compile files('libs/commons-codec-1.5.jar') 
compile files('libs/dom4j-1.6.1.jar') 
compile files('libs/stax-api-1.0.1.jar') 
compile files('libs/xml-apis-1.0.b2.jar') 
compile files('libs/xmlbeans.jar') 

應用程序啓動,但崩潰......

logcat的 http://pastebin.com/NG3AnW3z

文件 「supl_zak.xlsx」可以從here.

Screenshot of libs

有我的任何解決方案可以下載?

回答

2

不幸的是,由於拉入了第三方庫依賴關係,您不能在Android上直接使用Apache POI。此外,庫的大小會導致非常大的應用程序文件,這通常是不可能的/可取的。你甚至有時會超過Dalvik Android Bytecode編譯強加的限制。

有哪些討論如何獲得POI運行在Android上提供一些資源:

+0

感謝您的第一個鏈接!固定。但有新問題:http://pastebin.com/shd99Emg現在我該怎麼辦?我用第一個鏈接的那個罐子... – tonakriz

+1

對不起,我不知道這意味着什麼或者它如何修復,也許你可以發佈一個問題到github存儲庫? – centic

+0

好吧,我發現那個錯誤。我需要在我的gradle中使用核心庫。我希望它很快就會解決。謝謝! – tonakriz

2

原因是至少有一個庫(xmlbeans.jar)聲明瞭可能與Android使用的核心庫衝突的類。

xmlbeans聲明javax.xml包中的類 - Android也有this package和其他類中的類。

從錯誤消息:

If you are legitimately using some code that happens to be in a core package, then the easiest safe alternative you have is to repackage that code. That is, move the classes in question into your own package namespace.

基本上,構建工具認爲你應該建立一個核心庫,而是你正試圖使用​​與默認的Android衝突的庫來構建應用程序核心圖書館。它建議你將你的代碼從核心包移到不同的包中。

我的建議 - 停止使用試圖使用核心軟件包名稱並使用Android提供的XML功能的外部庫。

+0

好的。但是如何在不使用xmlbeans的情況下讀取XLSX文件? – tonakriz

+0

或者我該如何「將有問題的類移動到你自己的包名字空間中」?你能解釋一下嗎?我從來沒有與這樣的事情取得聯繫... – tonakriz

+0

Or2,是否有任何替代xmlbeans? – tonakriz

0

我有一個想法,你可以遵循: 你導入的一些jar是內部API,比如layoutlib s.jar,他們只是參與了編制,而不是在apk.If打包你想使用它們,只需創建一個在模塊的根名爲mylib中的文件夾,然後看圖片,跟着他們:

enter image description here

enter image description here

如果我的答案解決了您的問題,請採納它。

相關問題