0

I am trying to solve this problem for 4 hours and I am completely without hope.

I am using android studio for coding this application. I have created a simple activity which holds edit field for user name and password and next there is a button which is meant to be to submit data from these two edit fields.

I am using mysql connector/j and the java code is following:

package allanko.quizzerappandroid;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

import java.sql.*;

public class LoginActivity extends AppCompatActivity
{
    private static CDatabase db;

    @Override
    protected void onCreate( Bundle savedInstanceState )
    {
        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_login );

        db = new CDatabase();
    }

  /*
    public static CDatabase getDB()
    {
      return db;
    }*/

    public class CDatabase
    {
        private String db_name;
        private String db_user;
        private String db_pass;
        private Connection connection;
        private boolean isConnected;

        public CDatabase()
        {
            db_name = "jdbc:mysql://localhost:3306/quizzer?useSSL=false";
            db_user = "quizzer";
            db_pass = "pass";
            connection = null;

            if( connect() == true )
              isConnected = true;
            else
              isConnected = false;
            printResult();
        }

        private boolean connect()
        {
            try
            {
              connection = DriverManager.getConnection( db_name, db_user, db_pass );
              return true;
            }
            catch( Exception exc )
            {
              exc . printStackTrace();
              return false;
            }
        }

      private void printResult()
      {
          TextView dbText = (TextView)findViewById( R.id.dbText );

          if( ! isConnected )
            dbText . setText( "Connection to database failed" );
          else
            dbText . setText( "Connected to database." );
      }

      public ResultSet query( String query) throws SQLException
      {
          Statement statement = connection . createStatement();
          return statement . executeQuery( query );
      }

      public boolean isConnected()
      {
          return isConnected;
      }
    }
}

When I start this application on whether emulator or my phone, it every time write "Connection to database failed." and I am getting this from console:

W/art: Common causes for lock verification issues are non-optimized dex code
W/art: and incorrect proguard optimizations.
W/art: Class android.support.v4.util.LruCache failed lock verification and will run slower.
W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
W/System.err: java.sql.SQLException: java.lang.VerifyError: Verifier rejected class com.mysql.jdbc.CharsetMapping: void com.mysql.jdbc.CharsetMapping.<clinit>() failed to verify: void com.mysql.jdbc.CharsetMapping.<clinit>(): [0x4287] Invalid reg type for array index (Precise Reference: com.mysql.jdbc.MysqlCharset[]) (declaration of 'com.mysql.jdbc.CharsetMapping' appears in /data/app/allanko.quizzerappandroid-1/base.apk)
W/System.err:     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:963)
W/System.err:     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:896)
W/System.err:     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:885)
W/System.err:     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)
W/System.err:     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:877)
W/System.err:     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:873)
W/System.err:     at com.mysql.jdbc.Util.handleNewInstance(Util.java:422)
W/System.err:     at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:410)
W/System.err:     at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:328)
W/System.err:     at java.sql.DriverManager.getConnection(DriverManager.java:569)
W/System.err:     at java.sql.DriverManager.getConnection(DriverManager.java:219)
W/System.err:     at allanko.quizzerappandroid.LoginActivity$CDatabase.connect(LoginActivity.java:55)
W/System.err:     at allanko.quizzerappandroid.LoginActivity$CDatabase.<init>(LoginActivity.java:43)
W/System.err:     at allanko.quizzerappandroid.LoginActivity.onCreate(LoginActivity.java:19)
W/System.err:     at android.app.Activity.performCreate(Activity.java:6664)
W/System.err:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
W/System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
W/System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
W/System.err:     at android.app.ActivityThread.-wrap12(ActivityThread.java)
W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err:     at android.os.Looper.loop(Looper.java:154)
W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:6077)
W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
W/System.err: Caused by: java.lang.VerifyError: Verifier rejected class com.mysql.jdbc.CharsetMapping: void com.mysql.jdbc.CharsetMapping.<clinit>() failed to verify: void com.mysql.jdbc.CharsetMapping.<clinit>(): [0x4287] Invalid reg type for array index (Precise Reference: com.mysql.jdbc.MysqlCharset[]) (declaration of 'com.mysql.jdbc.CharsetMapping' appears in /data/app/allanko.quizzerappandroid-1/base.apk)
W/System.err:     at com.mysql.jdbc.CharsetMapping.getNumberOfCharsetsConfigured(CharsetMapping.java:687)
W/System.err:     at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:464)
W/System.err:     at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
W/System.err:     at java.lang.reflect.Constructor.newInstance0(Native Method)
W/System.err:     at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
W/System.err:     at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
W/System.err:   ... 19 more
W/gralloc_ranchu: Gralloc pipe failed

I am completely desperate because I tried to google everything that came to my mind and nothing worked.

Thanks in advance for your answers.

scarface
  • 574
  • 6
  • 20

2 Answers2

0

Hope that this link should help you in resolving the issue. It so happens that you would've been referring to the project instead of referring to the corresponding library.

The compiler flags problems of this kind where method signatures won't tally. JVM verifies the bytecode when the class is loaded, and throws a VerifyError when the bytecode tries to do something that it should not be allowed to.

Other possibilities to check on this can be:

  1. It can be because of change in the referenced libraries. Clean Project and followed by a Build might help!
  2. Restarting your IDE might also help as it can be the IDE's fault to refer an incorrect version of the necessary jar.
N00b Pr0grammer
  • 4,503
  • 5
  • 32
  • 46
0

I had same problem. (Sorry, I can't speak english well).

My solution was change MySql Driver x MariaDB Driver.

I think that problem is that there are two class with same name com.mysql.jdbc.CharsetMapping. When I use MariaDB, org.mariadb.jdbc.Driver I change second class to org.mariadb.jdbc.CharsetMapping, and problem solved.

I wish that this help you.

Best regards.