Я не понимаю, почему код не работает на Android, это тот же код в Java, и он работает на моем ноутбуке. Я уже искал в Google, Stackoverflow и Youtube, но не нашел причины. Во всех руководствах Youtube этот тип кода работает с android. Пример: https://www.youtube.com/watch?v=lM2vDPPx4Xg или https://www.youtube.com/watch?v=MnmEXqfV5BU
Вот код:
@Override
protected Void doInBackground(Void... voids) {
try{
Class c=Class.forName("org.postgresql.Driver");
Driver driver=(Driver) c.newInstance();
DriverManager.registerDriver(driver);
String url="jdbc:postgresql://url?sslmode=verify-ca&sslfactory=org.postgresql.ssl.DefaultJavaSSLFactory";
String username="username";
String password="pwd";
this.conn=DriverManager.getConnection(url,username,password);
//statement for make request
this.stmt=this.conn.createStatement();
System.out.println("Connecté !");
conn_load=false;
}catch (Exception e){
System.out.println("Connexion problem");
System.out.println(e.getCause());
}
return null;
}
В терминале windows код работает но не на android:
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Ljava/lang/management/ManagementFactory;
at org.postgresql.util.PGPropertyMaxResultBufferParser.adjustResultSize(PGPropertyMaxResultBufferParser.java:200)
at org.postgresql.util.PGPropertyMaxResultBufferParser.parseProperty(PGPropertyMaxResultBufferParser.java:37)
at org.postgresql.core.PGStream.setMaxResultBuffer(PGStream.java:643)
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:102)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:197)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:217)
at org.postgresql.Driver.makeConnection(Driver.java:458)
at org.postgresql.Driver.connect(Driver.java:260)
at java.sql.DriverManager.getConnection(DriverManager.java:569)
at java.sql.DriverManager.getConnection(DriverManager.java:219)
at com.devoteam.recrutement.model.bdd.BDD.doInBackground(BDD.java:54)
at com.devoteam.recrutement.model.bdd.BDD.doInBackground(BDD.java:12)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.ClassNotFoundException: Didn't find class "java.lang.management.ManagementFactory" on path: DexPathList[[zip file "/data/app/com.devoteam.recrutement-B8V00xTM4oetyFeYswlxVQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.devoteam.recrutement-B8V00xTM4oetyFeYswlxVQ==/lib/arm, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at org.postgresql.util.PGPropertyMaxResultBufferParser.adjustResultSize(PGPropertyMaxResultBufferParser.java:200)
at org.postgresql.util.PGPropertyMaxResultBufferParser.parseProperty(PGPropertyMaxResultBufferParser.java:37)
at org.postgresql.core.PGStream.setMaxResultBuffer(PGStream.java:643)
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:102)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:197)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:217)
at org.postgresql.Driver.makeConnection(Driver.java:458)
at org.postgresql.Driver.connect(Driver.java:260)
at java.sql.DriverManager.getConnection(DriverManager.java:569)
at java.sql.DriverManager.getConnection(DriverManager.java:219)
at com.devoteam.recrutement.model.bdd.BDD.doInBackground(BDD.java:54)
at com.devoteam.recrutement.model.bdd.BDD.doInBackground(BDD.java:12)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)