1
votes

Well, trying to access a postgresql Database using Android, I got the following, very surprising Exception:

    org.postgresql.util.PSQLException: Something unusual has occurred to cause the driver to fail. Please report this exception.
        at org.postgresql.Driver.connect(Driver.java:305)
        at java.sql.DriverManager.getConnection(DriverManager.java:179)
        at java.sql.DriverManager.getConnection(DriverManager.java:213)
        at org.pbdevelopement.cineapp.NetReader.getConnection(NetReader.java:42)
        at org.pbdevelopement.cineapp.MainActivity.getPersonalMovies(MainActivity.java:242)
        at org.pbdevelopement.cineapp.MainActivity.onCreate(MainActivity.java:115)
        at android.app.Activity.performCreate(Activity.java:6034)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1111)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2332)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2442)
        at android.app.ActivityThread.access$800(ActivityThread.java:156)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:211)
        at android.app.ActivityThread.main(ActivityThread.java:5373)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
    Caused by: android.os.NetworkOnMainThreadException
        at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1151)
        at java.net.InetAddress.lookupHostByName(InetAddress.java:418)
        at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
        at java.net.InetAddress.getByName(InetAddress.java:305)
        at java.net.InetSocketAddress.(InetSocketAddress.java:105)
        at java.net.InetSocketAddress.(InetSocketAddress.java:90)
        at org.postgresql.core.PGStream.(PGStream.java:61)
        at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:129)
        at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:65)
        at org.postgresql.jdbc.PgConnection.(PgConnection.java:159)
        at org.postgresql.Driver.makeConnection(Driver.java:415)
        at org.postgresql.Driver.connect(Driver.java:283)
        ... 18 more

I have no clue how to fix this, neither do I have a clue where to report it to... Does anybody have any ideas?

1
You can report Postgresql JDBC bugs here: jdbc.postgresql.org/community/mailinglist.html - bradimus
Why this question is down-voted? - user2004685
@bradimus what do you think, is this worth being reported? Or was I just to stupid to use their driver properly and don't deserve any better? ;) - Maverick283

1 Answers

4
votes

It seems that you are trying to perform your database request through a network operation on the applications Main Thread. This throws the exception android.os.NetworkOnMainThreadException because every network operation in Android must be started in an own thread. Try to perform your Database request in AsyncTask.

AsyncTask