android – How to overcome "java.lang.BootstrapMethodError: Exception from call site #46 bootstrap method" error?-ThrowExceptions

Exception or error:

I’m really new to Android Studio. I try to connect to database phpMyAdmin to make a login function.

Here I the code login page(MainActivity):–



import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import static java.lang.Class.forName;

public class MainActivity extends AppCompatActivity {



    private EditText no_kt;
    private EditText password;
    private Button login_bt;
    Connection connnect=null;
    ConnectionClass DatabaseConnection;
    PreparedStatement pst;
    ResultSet rs;


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

        no_kt = findViewById(R.id.no_kt);
        password = findViewById(R.id.password);
        login_bt = findViewById(R.id.login_bt);

        DatabaseConnection = new ConnectionClass();

        connnect=DatabaseConnection.ConnectDB();

        no_kt.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                enableButton();
            }

            @Override
            public void afterTextChanged(Editable s) {
            }
        });
        password.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                enableButton();
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

        login_bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {

                    String query="SELECT * FROM user";
                    pst=connnect.prepareStatement(query);
                    rs=pst.executeQuery();
                    int count=0;
                    while(rs.next()){
                        count++;
                    }

                    if(count>0){

                        LoginSuccess();

                    }else{
                        Toast.makeText(getApplicationContext(),"No K/Tangan atau Kata Laluan tidak sah",Toast.LENGTH_LONG).show();
                    }

                }catch (Exception e){
                    Toast.makeText(getApplicationContext(),e.toString(),Toast.LENGTH_LONG).show();
                }
            }
        });


    }





    public void LoginSuccess(){
        Intent intent = new Intent(this, home.class);
        startActivity(intent);

    }

    public void enableButton(){

        if((no_kt.getText().toString()).equals("")||(password.getText().toString()).equals("")){

            login_bt.setEnabled(false);
        }

        else{
            login_bt.setEnabled(true);
        }
    }
}

Here also the connection class for database connection:—


import android.os.StrictMode;

import java.sql.Connection;
import java.sql.DriverManager;


class ConnectionClass {

    public Connection ConnectDB(){

        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);

        Connection conn=null;

        try{
            Class.forName("com.mysql.cj.jdbc.Driver");
            conn =DriverManager.getConnection("jdbc:mysql://localhost:3306/pkb_db","root","");

        }catch (Exception e){ }
        return conn;
    }
}

And here are the error from Logcat:—

    Process: com.e.test, PID: 25788
    java.lang.BootstrapMethodError: Exception from call site #46 bootstrap method
        at com.mysql.cj.jdbc.AbandonedConnectionCleanupThread.<clinit>(AbandonedConnectionCleanupThread.java:58)
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:453)
        at java.lang.Class.forName(Class.java:378)
        at com.mysql.cj.jdbc.NonRegisteringDriver.<clinit>(NonRegisteringDriver.java:97)
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:453)
        at java.lang.Class.forName(Class.java:378)
        at com.e.test.ConnectionClass.ConnectDB(ConnectionClass.java:19)
        at com.e.test.MainActivity.onCreate(MainActivity.java:44)
        at android.app.Activity.performCreate(Activity.java:7136)
        at android.app.Activity.performCreate(Activity.java:7127)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: java.lang.ClassCastException: Bootstrap method returned null

Can you guys please tell what error is it? I’ve never heard of this error before..

Please help me guys….. 🙁

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *