ANDROID: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/mysql/cj/MysqlType
ANDROID: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/mysql/cj/MysqlType
我正在尝试将我的项目与 mysql 数据库连接,但我在驱动程序中收到此错误:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.catalyst, PID: 12531
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/mysql/cj/MysqlType;
at com.mysql.cj.protocol.a.NativeProtocol.findMysqlType(NativeProtocol.java:1466)
at com.mysql.cj.protocol.a.ColumnDefinitionReader.unpackField(ColumnDefinitionReader.java:134)
at com.mysql.cj.protocol.a.ColumnDefinitionReader.read(ColumnDefinitionReader.java:77)
at com.mysql.cj.protocol.a.ColumnDefinitionReader.read(ColumnDefinitionReader.java:40)
at com.mysql.cj.protocol.a.NativeProtocol.read(NativeProtocol.java:1588)
at com.mysql.cj.protocol.a.TextResultsetReader.read(TextResultsetReader.java:68)
at com.mysql.cj.protocol.a.TextResultsetReader.read(TextResultsetReader.java:48)
at com.mysql.cj.protocol.a.NativeProtocol.read(NativeProtocol.java:1601)
at com.mysql.cj.protocol.a.NativeProtocol.readAllResults(NativeProtocol.java:1655)
at com.mysql.cj.NativeSession.loadServerVariables(NativeSession.java:765)
at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1303)
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:964)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:823)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:453)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
at java.sql.DriverManager.getConnection(DriverManager.java:569)
at java.sql.DriverManager.getConnection(DriverManager.java:219)
at modelo.Conexion.conectar(Conexion.java:24)
at modelo.EnviarIngresos.ejecutarServicio(EnviarIngresos.java:27)
at GUIs.QRscanner.enviarIngreso(QRscanner.java:75)
at GUIs.QRscanner.onClick(QRscanner.java:42)
at android.view.View.performClick(View.java:6297)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119)
at android.view.View$PerformClick.run(View.java:24797)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6626)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
Caused by: java.lang.ClassNotFoundException: com.mysql.cj.MysqlType
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.mysql.cj.protocol.a.NativeProtocol.findMysqlType(NativeProtocol.java:1466)
at com.mysql.cj.protocol.a.ColumnDefinitionReader.unpackField(ColumnDefinitionReader.java:134)
at com.mysql.cj.protocol.a.ColumnDefinitionReader.read(ColumnDefinitionReader.java:77)
at com.mysql.cj.protocol.a.ColumnDefinitionReader.read(ColumnDefinitionReader.java:40)
at com.mysql.cj.protocol.a.NativeProtocol.read(NativeProtocol.java:1588)
at com.mysql.cj.protocol.a.TextResultsetReader.read(TextResultsetReader.java:68)
at com.mysql.cj.protocol.a.TextResultsetReader.read(TextResultsetReader.java:48)
at com.mysql.cj.protocol.a.NativeProtocol.read(NativeProtocol.java:1601)
at com.mysql.cj.protocol.a.NativeProtocol.readAllResults(NativeProtocol.java:1655)
at com.mysql.cj.NativeSession.loadServerVariables(NativeSession.java:765)
at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1303)
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:964)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:823)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:453)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
at java.sql.DriverManager.getConnection(DriverManager.java:569)
at java.sql.DriverManager.getConnection(DriverManager.java:219)
at modelo.Conexion.conectar(Conexion.java:24)
at modelo.EnviarIngresos.ejecutarServicio(EnviarIngresos.java:27)
at GUIs.QRscanner.enviarIngreso(QRscanner.java:75)
at GUIs.QRscanner.onClick(QRscanner.java:42)
at android.view.View.performClick(View.java:6297)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119)
at android.view.View$PerformClick.run(View.java:24797)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6626)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Ljava/sql/SQLType;
at com.mysql.cj.protocol.a.NativeProtocol.findMysqlType(NativeProtocol.java:1466)
at com.mysql.cj.protocol.a.ColumnDefinitionReader.unpackField(ColumnDefinitionReader.java:134)
at com.mysql.cj.protocol.a.ColumnDefinitionReader.read(ColumnDefinitionReader.java:77)
at com.mysql.cj.protocol.a.ColumnDefinitionReader.read(ColumnDefinitionReader.java:40)
at com.mysql.cj.protocol.a.NativeProtocol.read(NativeProtocol.java:1588)
at com.mysql.cj.protocol.a.TextResultsetReader.read(TextResultsetReader.java:68)
at com.mysql.cj.protocol.a.TextResultsetReader.read(TextResultsetReader.java:48)
at com.mysql.cj.protocol.a.NativeProtocol.read(NativeProtocol.java:1601)
at com.mysql.cj.protocol.a.NativeProtocol.readAllResults(NativeProtocol.java:1655)
at com.mysql.cj.NativeSession.loadServerVariables(NativeSession.java:765)
at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1303)
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:964)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:823)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:453)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
at java.sql.DriverManager.getConnection(DriverManager.java:569)
at java.sql.DriverManager.getConnection(DriverManager.java:219)
at modelo.Conexion.conectar(Conexion.java:24)
at modelo.EnviarIngresos.ejecutarServicio(EnviarIngresos.java:27)
at GUIs.QRscanner.enviarIngreso(QRscanner.java:75)
at GUIs.QRscanner.onClick(QRscanner.java:42)
at android.view.View.performClick(View.java:6297)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119)
at android.view.View$PerformClick.run(View.java:24797)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6626)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
Caused by: java.lang.ClassNotFoundException: Didn't find class "java.sql.SQLType" on path: DexPathList[[zip file "/data/app/com.example.catalyst-r_unhHUpn3kJ_xqUGFYc4w==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.catalyst-fumFeudS3H2K2UqSBclr7A==/lib/arm, /system/lib, /system/vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.mysql.cj.protocol.a.NativeProtocol.findMysqlType(NativeProtocol.java:1466)
at com.mysql.cj.protocol.a.ColumnDefinitionReader.unpackField(ColumnDefinitionReader.java:134)
at com.mysql.cj.protocol.a.ColumnDefinitionReader.read(ColumnDefinitionReader.java:77)
at com.mysql.cj.protocol.a.ColumnDefinitionReader.read(ColumnDefinitionReader.java:40)
at com.mysql.cj.protocol.a.NativeProtocol.read(NativeProtocol.java:1588)
at com.mysql.cj.protocol.a.TextResultsetReader.read(TextResultsetReader.java:68)
at com.mysql.cj.protocol.a.TextResultsetReader.read(TextResultsetReader.java:48)
at com.mysql.cj.protocol.a.NativeProtocol.read(NativeProtocol.java:1601)
at com.mysql.cj.protocol.a.NativeProtocol.readAllResults(NativeProtocol.java:1655)
at com.mysql.cj.NativeSession.loadServerVariables(NativeSession.java:765)
at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1303)
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:964)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:823)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:453)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
at java.sql.DriverManager.getConnection(DriverManager.java:569)
at java.sql.DriverManager.getConnection(DriverManager.java:219)
at modelo.Conexion.conectar(Conexion.java:24)
at modelo.EnviarIngresos.ejecutarServicio(EnviarIngresos.java:27)
at GUIs.QRscanner.enviarIngreso(QRscanner.java:75)
at GUIs.QRscanner.onClick(QRscanner.java:42)
at android.view.View.performClick(View.java:6297)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119)
at android.view.View$PerformClick.run(View.java:24797)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6626)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
这些是我的依赖项(gradle):
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.google.android.gms:play-services-maps:17.0.1'
implementation files('libs\UMLDesignTool.jar')
implementation files('libs/mysql-connector-java-8.0.25.jar')
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.4.0'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.4.0'
testImplementation 'org.junit.platform:junit-platform-launcher:1.0.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.journeyapps:zxing-android-embedded:3.4.0'
androidTestImplementation 'org.junit.jupiter:junit-jupiter'
androidTestImplementation 'org.testng:testng:6.9.6'
implementation 'com.android.volley:volley:1.2.0'
}
这是我进行连接的项目的 class:
import android.os.StrictMode;
import java.sql.Connection;
import java.sql.DriverManager;
public class Conexion {
private static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
private static final String DB_URL = "jdbc:mysql://localhost:3306/databasename";
private static final String USER = "root";
private static final String PASS = "";
public Connection conectar(){
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Connection conexion = null;
try {
Class.forName(JDBC_DRIVER).newInstance();
conexion= DriverManager.getConnection(DB_URL, USER, PASS);
} catch (Exception ex) {
ex.printStackTrace();
}
return conexion;
}
}
错误说我没有驱动,但是我有,我不知道怎么办,也找不到和我有同样错误的post
您不能在 Android 上使用 MySQL Connector/J 的最新版本,因为它使用了 Android 上不可用的类型和功能。这里的具体原因是com.mysql.cj.MysqlType
类型实现了java.sql.SQLType
(在Java8/JDBC4.2中引入),根据错误判断这个类型在[=中不存在20=]。过去,我也看到过与在正则表达式中使用命名组相关的错误,这些错误在 Android.
上也不支持(或曾经不支持)
一般来说,您不应该在 Android 上使用 JDBC,最好使用 REST API 在您的 Android 应用程序和数据库。但是,如果你真的想使用 Android 中的 MySQL,你将不得不使用 MySQL Connector/J 5.1.x 而不是 8.0.x.
我正在尝试将我的项目与 mysql 数据库连接,但我在驱动程序中收到此错误:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.catalyst, PID: 12531
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/mysql/cj/MysqlType;
at com.mysql.cj.protocol.a.NativeProtocol.findMysqlType(NativeProtocol.java:1466)
at com.mysql.cj.protocol.a.ColumnDefinitionReader.unpackField(ColumnDefinitionReader.java:134)
at com.mysql.cj.protocol.a.ColumnDefinitionReader.read(ColumnDefinitionReader.java:77)
at com.mysql.cj.protocol.a.ColumnDefinitionReader.read(ColumnDefinitionReader.java:40)
at com.mysql.cj.protocol.a.NativeProtocol.read(NativeProtocol.java:1588)
at com.mysql.cj.protocol.a.TextResultsetReader.read(TextResultsetReader.java:68)
at com.mysql.cj.protocol.a.TextResultsetReader.read(TextResultsetReader.java:48)
at com.mysql.cj.protocol.a.NativeProtocol.read(NativeProtocol.java:1601)
at com.mysql.cj.protocol.a.NativeProtocol.readAllResults(NativeProtocol.java:1655)
at com.mysql.cj.NativeSession.loadServerVariables(NativeSession.java:765)
at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1303)
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:964)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:823)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:453)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
at java.sql.DriverManager.getConnection(DriverManager.java:569)
at java.sql.DriverManager.getConnection(DriverManager.java:219)
at modelo.Conexion.conectar(Conexion.java:24)
at modelo.EnviarIngresos.ejecutarServicio(EnviarIngresos.java:27)
at GUIs.QRscanner.enviarIngreso(QRscanner.java:75)
at GUIs.QRscanner.onClick(QRscanner.java:42)
at android.view.View.performClick(View.java:6297)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119)
at android.view.View$PerformClick.run(View.java:24797)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6626)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
Caused by: java.lang.ClassNotFoundException: com.mysql.cj.MysqlType
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.mysql.cj.protocol.a.NativeProtocol.findMysqlType(NativeProtocol.java:1466)
at com.mysql.cj.protocol.a.ColumnDefinitionReader.unpackField(ColumnDefinitionReader.java:134)
at com.mysql.cj.protocol.a.ColumnDefinitionReader.read(ColumnDefinitionReader.java:77)
at com.mysql.cj.protocol.a.ColumnDefinitionReader.read(ColumnDefinitionReader.java:40)
at com.mysql.cj.protocol.a.NativeProtocol.read(NativeProtocol.java:1588)
at com.mysql.cj.protocol.a.TextResultsetReader.read(TextResultsetReader.java:68)
at com.mysql.cj.protocol.a.TextResultsetReader.read(TextResultsetReader.java:48)
at com.mysql.cj.protocol.a.NativeProtocol.read(NativeProtocol.java:1601)
at com.mysql.cj.protocol.a.NativeProtocol.readAllResults(NativeProtocol.java:1655)
at com.mysql.cj.NativeSession.loadServerVariables(NativeSession.java:765)
at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1303)
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:964)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:823)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:453)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
at java.sql.DriverManager.getConnection(DriverManager.java:569)
at java.sql.DriverManager.getConnection(DriverManager.java:219)
at modelo.Conexion.conectar(Conexion.java:24)
at modelo.EnviarIngresos.ejecutarServicio(EnviarIngresos.java:27)
at GUIs.QRscanner.enviarIngreso(QRscanner.java:75)
at GUIs.QRscanner.onClick(QRscanner.java:42)
at android.view.View.performClick(View.java:6297)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119)
at android.view.View$PerformClick.run(View.java:24797)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6626)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Ljava/sql/SQLType;
at com.mysql.cj.protocol.a.NativeProtocol.findMysqlType(NativeProtocol.java:1466)
at com.mysql.cj.protocol.a.ColumnDefinitionReader.unpackField(ColumnDefinitionReader.java:134)
at com.mysql.cj.protocol.a.ColumnDefinitionReader.read(ColumnDefinitionReader.java:77)
at com.mysql.cj.protocol.a.ColumnDefinitionReader.read(ColumnDefinitionReader.java:40)
at com.mysql.cj.protocol.a.NativeProtocol.read(NativeProtocol.java:1588)
at com.mysql.cj.protocol.a.TextResultsetReader.read(TextResultsetReader.java:68)
at com.mysql.cj.protocol.a.TextResultsetReader.read(TextResultsetReader.java:48)
at com.mysql.cj.protocol.a.NativeProtocol.read(NativeProtocol.java:1601)
at com.mysql.cj.protocol.a.NativeProtocol.readAllResults(NativeProtocol.java:1655)
at com.mysql.cj.NativeSession.loadServerVariables(NativeSession.java:765)
at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1303)
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:964)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:823)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:453)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
at java.sql.DriverManager.getConnection(DriverManager.java:569)
at java.sql.DriverManager.getConnection(DriverManager.java:219)
at modelo.Conexion.conectar(Conexion.java:24)
at modelo.EnviarIngresos.ejecutarServicio(EnviarIngresos.java:27)
at GUIs.QRscanner.enviarIngreso(QRscanner.java:75)
at GUIs.QRscanner.onClick(QRscanner.java:42)
at android.view.View.performClick(View.java:6297)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119)
at android.view.View$PerformClick.run(View.java:24797)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6626)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
Caused by: java.lang.ClassNotFoundException: Didn't find class "java.sql.SQLType" on path: DexPathList[[zip file "/data/app/com.example.catalyst-r_unhHUpn3kJ_xqUGFYc4w==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.catalyst-fumFeudS3H2K2UqSBclr7A==/lib/arm, /system/lib, /system/vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.mysql.cj.protocol.a.NativeProtocol.findMysqlType(NativeProtocol.java:1466)
at com.mysql.cj.protocol.a.ColumnDefinitionReader.unpackField(ColumnDefinitionReader.java:134)
at com.mysql.cj.protocol.a.ColumnDefinitionReader.read(ColumnDefinitionReader.java:77)
at com.mysql.cj.protocol.a.ColumnDefinitionReader.read(ColumnDefinitionReader.java:40)
at com.mysql.cj.protocol.a.NativeProtocol.read(NativeProtocol.java:1588)
at com.mysql.cj.protocol.a.TextResultsetReader.read(TextResultsetReader.java:68)
at com.mysql.cj.protocol.a.TextResultsetReader.read(TextResultsetReader.java:48)
at com.mysql.cj.protocol.a.NativeProtocol.read(NativeProtocol.java:1601)
at com.mysql.cj.protocol.a.NativeProtocol.readAllResults(NativeProtocol.java:1655)
at com.mysql.cj.NativeSession.loadServerVariables(NativeSession.java:765)
at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1303)
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:964)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:823)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:453)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
at java.sql.DriverManager.getConnection(DriverManager.java:569)
at java.sql.DriverManager.getConnection(DriverManager.java:219)
at modelo.Conexion.conectar(Conexion.java:24)
at modelo.EnviarIngresos.ejecutarServicio(EnviarIngresos.java:27)
at GUIs.QRscanner.enviarIngreso(QRscanner.java:75)
at GUIs.QRscanner.onClick(QRscanner.java:42)
at android.view.View.performClick(View.java:6297)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119)
at android.view.View$PerformClick.run(View.java:24797)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6626)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
这些是我的依赖项(gradle):
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.google.android.gms:play-services-maps:17.0.1'
implementation files('libs\UMLDesignTool.jar')
implementation files('libs/mysql-connector-java-8.0.25.jar')
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.4.0'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.4.0'
testImplementation 'org.junit.platform:junit-platform-launcher:1.0.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.journeyapps:zxing-android-embedded:3.4.0'
androidTestImplementation 'org.junit.jupiter:junit-jupiter'
androidTestImplementation 'org.testng:testng:6.9.6'
implementation 'com.android.volley:volley:1.2.0'
}
这是我进行连接的项目的 class:
import android.os.StrictMode;
import java.sql.Connection;
import java.sql.DriverManager;
public class Conexion {
private static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
private static final String DB_URL = "jdbc:mysql://localhost:3306/databasename";
private static final String USER = "root";
private static final String PASS = "";
public Connection conectar(){
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Connection conexion = null;
try {
Class.forName(JDBC_DRIVER).newInstance();
conexion= DriverManager.getConnection(DB_URL, USER, PASS);
} catch (Exception ex) {
ex.printStackTrace();
}
return conexion;
}
}
错误说我没有驱动,但是我有,我不知道怎么办,也找不到和我有同样错误的post
您不能在 Android 上使用 MySQL Connector/J 的最新版本,因为它使用了 Android 上不可用的类型和功能。这里的具体原因是com.mysql.cj.MysqlType
类型实现了java.sql.SQLType
(在Java8/JDBC4.2中引入),根据错误判断这个类型在[=中不存在20=]。过去,我也看到过与在正则表达式中使用命名组相关的错误,这些错误在 Android.
一般来说,您不应该在 Android 上使用 JDBC,最好使用 REST API 在您的 Android 应用程序和数据库。但是,如果你真的想使用 Android 中的 MySQL,你将不得不使用 MySQL Connector/J 5.1.x 而不是 8.0.x.