我的 android 应用程序需要使用 JDBC 与 SQL Server 一起工作, 所以我添加了 sqlljdbc42.jar模块中的文件,
但是我在 Build - Gradle 中出错,下面是我的 Gradle Console :
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAnimatedVectorDrawable2400Alpha1Library UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72400Alpha1Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42400Alpha1Library UP-TO-DATE
:app:prepareComAndroidSupportSupportVectorDrawable2400Alpha1Library 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:processDebugJavaRes UP-TO-DATE
:app:compileDebugJava
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources
:app:preDexDebug
AGPBI: {"kind":"SIMPLE","text":"PARSE ERROR:","position":{},"original":"PARSE ERROR:"}
AGPBI: {"kind":"SIMPLE","text":"unsupported class file version 52.0","position":{},"original":"unsupported class file version 52.0"}
AGPBI: {"kind":"SIMPLE","text":"...while parsing com/microsoft/sqlserver/jdbc/ActivityCorrelator.class","position":{},"original":"...while parsing com/microsoft/sqlserver/jdbc/ActivityCorrelator.class"}
AGPBI: {"kind":"SIMPLE","text":"1 error; aborting","position":{},"original":"1 error; aborting"}
BUILD FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:preDexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_40\bin\java.exe'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
在 Gradle Build 窗口中我得到了这个:
Error:Execution failed for task ':app:preDexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_40\bin\java.exe'' finished with non-zero exit value 1
连接字符串工作正常,我的 MainActivity.java 文件包含:
public class MainActivity extends ActionBarActivity {
TextView tv;
Connection DbConn;
Statement stmt;
ResultSet reset;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView) findViewById(R.id.textView);
try {
Log.e("Inside the Try Block", "Pre - Done");
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
DbConn = DriverManager.getConnection("{connection string}");
Log.e("Connection","open");
stmt = DbConn.createStatement();
reset = stmt.executeQuery(" select * from Members");
tv.setText("User Name : "+reset.getString(1)+", Name : "+reset.getString(2));
DbConn.close();
} catch(Exception e) {
Log.e("Error connection", "" + e.getMessage());
e.printStackTrace();
}
}
}
最佳答案
该错误是由于编译器的字节码版本与包含的 .jar
存档中的类不匹配引起的
见got unsupported class file version 52 0 after including a module to a project详情
编辑:使用 sqljdbc41.jar
而不是 sqljdbc42.jar
应该可以解决问题
关于android - gradle 中的解析错误 - ExecException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38109160/