0

I get this strange error:

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server

I already tried to reinstall mysql but this was useless. Internet permissions are already in the manifest file.

this the screen of the code and the actual error

this is the code in the "onCreate" function

halfer
  • 19,824
  • 17
  • 99
  • 186

2 Answers2

0

It might be caused by that localhost (if running on a real device, local host means that device).

0

Solution:

Try the below steps.

Step1:

Make an inner class in your activity as:

private class LoadDatabase extends AsyncTask<Void, Void, Void> {
    @Override
    protected String doInBackground(String... urls) {
        DBConnect connection = new DBConnect();
        return null;
    }
}

Step2:

Call this in your onCreate() as shown below:

new LoadDatabase().execute()

Hope it works.

Ümañg ßürmån
  • 9,695
  • 4
  • 24
  • 41