0

I have managed to pinpoint two of the mistakes I had and will therefore update my question.

Firstly, my previous error:

java.lang.ClassCastException: Bootstrap method returned null

was fixed by simply adding this line to build.graddle (app) dependencies:

implementation group: 'com.google.protobuf', name: 'protobuf-java', version: '3.6.0'

So that was nice, However this did not solve all my issues. This is my current register button method:

registerButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            try {
                conn = Utils.getConnection();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

As you can see I am focusing solely on getting a connection as it seems to be the heart of the problem. In debugging I also modified getConnection() to the following:

public static Connection getConnection() {
    String driver = "com.mysql.cj.jdbc.Driver"; //com.mysql.jdbc.Driver doesn't work either
    String url = "url";
    String username = "user";
    String password = "pass";

    try {
        Class.forName(driver);
    } catch (ClassNotFoundException e) {
        System.out.println("Where is your MySQL JDBC Driver?");
        e.printStackTrace();
        return null;
    }

    System.out.println("MySQL JDBC Driver Registered!");
    Connection connection = null;

    try {
        connection = DriverManager.getConnection(url,username, password);
    } catch (SQLException e) {
        System.out.println("Connection Failed! Check output console");
        e.printStackTrace();
        return null;
    }
    if (connection != null) {
        System.out.println("You made it, take control your database now!");
    } else {
        System.out.println("Failed to make connection!");
    }
    return connection;
}

And this is the error that I am receiving now:

I/System.out: Connection Failed! Check output console
W/System.err: java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
W/System.err: Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
          The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
Caused by: java.net.SocketException: socket failed: EACCES (Permission denied)

I will keep this up to date on further changes. Again, if the issue is obvious I apologize in advance. Thanks for the help!

Ari
  • 13
  • 3
  • `registerUser(connection, .... )` Where you declare `connection` ? – John Joe Jul 30 '18 at 02:10
  • @JohnJoe, I have moved connection around quite a bit, right now I have it declared as a class variable. It seems like it has to be something else because I’ve tried it everywhere. – Ari Jul 30 '18 at 02:16
  • Based on the stack trace, it seems that your `registerUser` method is separate from the root of the problem because it never appears there. Instead, the exception occurs during your `getConnection` method. – FThompson Jul 30 '18 at 02:39
  • `stmt.execute("INSERT INTO user (first, last, email, salt, password) VALUES ('"+first.toLowerCase()+"', '"+last.toLowerCase()+"', '"+email.toLowerCase()+"', '"+salt+"', '"+hashedPassword+"')");` – John Joe Jul 30 '18 at 02:41
  • @Vulcan I agree, however I do not know how to fix it. – Ari Jul 30 '18 at 02:42
  • I only found [one other Google search result](https://community.particle.io/t/android-sdk-initialization-error/42944) based on the `Bootstrap method returned null` error and the solution there was to declare that the project requires Java 8 compatibility. The latest major release of MySQL Connector/J requires Java 8, so this could be the source of the problem if you are running a Java version <8. Maybe try that solution? – FThompson Jul 30 '18 at 02:43
  • @Vulcan I will try that, let you guys know how it goes – Ari Jul 30 '18 at 03:01
  • I updated the issue, java 8 was unfortunately not a solution. – Ari Jul 30 '18 at 23:14
  • Java 8 seems to be the solution to *that* problem. Regarding the new error, I found this other question that addresses the `EACCES (Permission denied)` error: https://stackoverflow.com/q/11273197/1247781 – FThompson Jul 31 '18 at 11:00
  • So There is no more issue with `EACCES (Permission denied)` but now I am getting error `java.sql.SQLNonTransientConnectionException: Could not create connection to database server.` `Caused by: android.os.NetworkOnMainThreadException` Looking into it. – Ari Jul 31 '18 at 17:27

0 Answers0