I'm trying to get an app I'm developing to connect to a Postgresql server. I've downloaded postgresql-42.2.5.jre7 from the official Postgresql JDBC driver page, dropped the jar in the libs directory, added a line to the classpath so it will compile. Everything works fine until I actually try to make a connection, at which point I get this error:
Caused by: java.lang.ClassNotFoundException: Didn't find class "java.util.Locale$Category" on path: DexPathList[[zip file "/data/app/swca.lithicdebitagetally-2/base.apk"],nativeLibraryDirectories=[/data/app/swca.lithicdebitagetally-2/lib/arm, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at org.postgresql.util.GT.<init>(GT.java:35)
at org.postgresql.util.GT.<clinit>(GT.java:21)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:292)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195)
at org.postgresql.Driver.makeConnection(Driver.java:454)
at org.postgresql.Driver.connect(Driver.java:256)
at java.sql.DriverManager.getConnection(DriverManager.java:179)
at java.sql.DriverManager.getConnection(DriverManager.java:213)
at swca.lithicdebitagetally.UploadData.doInBackground(UploadData.java:31)
at swca.lithicdebitagetally.UploadData.doInBackground(UploadData.java:14)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Suppressed: java.lang.ClassNotFoundException: java.util.Locale$Category
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 18 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
I'm really stumped as to why its shooting this, though it may have something to do with the version of the driver I'm using. (It seems like I should be using 42.2.5 which is supposed to be Java 8 compatible but I received a compile error whenever I used it).
Here is code that calls it:
protected String doInBackground(String... params){
Connection connection = null;
String result = "success";
try{
Class.forName("org.postgresql.Driver");
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
result = "fail";
}
try {
connection = DriverManager.getConnection(
"jdbc:postgresql://**.*.****.***:***/*****", "****",
"****");
} catch (SQLException e) {
System.out.println("Connection Failed! Check output console");
e.printStackTrace();
result = "fail";
}
return result;
}