繁体   English   中英

java.exe以非零退出值1结束

[英]java.exe finished with non-zero exit value 1

刚开始,我并不是想从Android中的.xlsx文件中读取单元格,我已经尝试了几乎所有我用Google搜索的内容,但每次(在两台不同的PC上,都是Java 1.7.0_79)我都是尝试构建(运行)此应用程序,它以相同的错误结束:

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和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”可以从这里下载

图书馆

libs的屏幕截图

我有什么解决方案吗?

原因是至少有一个库(xmlbeans.jar)声明可能与Android使用的核心库冲突的类。

xmlbeansjavax.xml包中声明了类--Android也包含此包中的类和其他类似的类。

从错误消息:

如果您合法地使用恰好位于核心软件包中的某些代码,那么最简单的安全替代方法是重新打包该代码。 也就是说,将有问题的类移动到您自己的包命名空间中

基本上,构建工具认为您应该构建核心库,而是尝试使用与默认Android核心库冲突的库来构建应用程序。 这表明你的核心包移动你的代码到不同的包。

我的建议 - 停止使用外部库,尝试使用核心软件包名称并使用Android提供的XML功能。

遗憾的是,由于引入了第三方库依赖关系,您无法在Android上直接使用Apache POI。此外,库的大小会导致非常大的应用程序文件,这通常是不可能/不可取的。 您甚至有时会超过Dalvik Android字节编译所施加的限制。

有一些资源可以讨论如何在Android上运行POI:

问题:java.exe以非零退出值1结束

解决方案:为了解决这个问题,我尝试了大多数解决方案,然后一次又一次地尝试。

终于找到了解决这个问题的方法。

这些是您应该尝试解决问题的可能解决方案,据我所知,它肯定会解决您的问题。

  1. 清理并重建您的项目。
  2. 请检查所有库是否已更新,并且gradle build版本也已更新。
  3. 尝试增加你的Java堆大小。
  4. 不要在代码中使用lambda表达式或语法。 在我的情况下,这是问题因为我使用lambda表达式,当我使用lambda表达式时,它需要在build.gradle(app)文件中声明

compileOptions {targetCompatibility 1.8 sourceCompatibility 1.8}

这个。

这是我遇到的实际问题,请从build.gradle文件中删除此compileOptions声明,或使用与您的Gradle版本兼容的正确版本。

谢谢

我希望这个解决方案能够帮助您解决问题。

我有一个想法你可以遵循:你导入的一些罐子是内部API,比如layoutlibs.jar,它们只涉及编译,而不是打包在apk中。如果你想使用它们,只需在根目录中创建一个名为mylib的文件夹。模块,然后看图片,按照它们:

在此输入图像描述

在此输入图像描述

如果我的答案解决了您的问题,请采纳它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM