-2
Oie I have a problem with an app in Android Studio, it compiles and runs on my phone, but when I click on some button it gives this error.
Error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.tcc, PID: 11613
java.lang.NoSuchMethodError: No virtual method group(Ljava/lang/String;)Ljava/lang/String; in class Ljava/util/regex/Matcher; or its super classes (declaration of 'java.util.regex.Matcher' appears in /system/framework/core-libart.jar)
at com.mysql.cj.conf.ConnectionUrlParser.isConnectionStringSupported(ConnectionUrlParser.java:152)
at com.mysql.cj.conf.ConnectionUrl.acceptsUrl(ConnectionUrl.java:317)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:185)
at java.sql.DriverManager.getConnection(DriverManager.java:179)
at java.sql.DriverManager.getConnection(DriverManager.java:213)
at com.example.tcc.ModelConnection.ConnectionFactory.getConnection(ConnectionFactory.java:21)
at com.example.tcc.MainActivity$1.onClick(MainActivity.java:30)
at android.view.View.performClick(View.java:5716)
at android.widget.TextView.performClick(TextView.java:10926)
at android.view.View$PerformClick.run(View.java:22596)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
The button calls a method to connect to the database,the database you are using is Mysql and I am using the connection driver version 8.0.21, I will show the codes...
Activity_main.xml
<Button
android:id="@+id/btnConectar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="39dp"
android:text="Conectar"
app:layout_constraintBaseline_toBaselineOf="@+id/btnCadastrar"
app:layout_constraintEnd_toStartOf="@+id/btnCadastrar" />
<Button
android:id="@+id/btnCadastrar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="79dp"
android:layout_marginBottom="229dp"
android:text="Cadastrar"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<TextView
android:id="@+id/lblCon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="63dp"
android:text="Desconectado"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btnCadastrar" />
<EditText
android:id="@+id/txtNome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="191dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Nome" />
<EditText
android:id="@+id/txtSenha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="54dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintStart_toStartOf="@+id/txtNome"
app:layout_constraintTop_toBottomOf="@+id/txtNome"
tools:text="Senha" />
Mainactivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnConectar = (Button) findViewById(R.id.btnConectar);
ConnectionFactory con = new ConnectionFactory();
final TextView lblCon = findViewById(R.id.lblCon);
btnConectar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try(Connection con = new ConnectionFactory().getConnection()){
Toast.makeText(MainActivity.this, "Conectado", Toast.LENGTH_SHORT).show();
lblCon.setText("Conectado");
}catch (Exception e){
lblCon.setText("N foi");
Log.i(TAG, "onClick: "+e.getMessage());
}
}
});
}
}
Connectionfactory.java.
public ResultSet rs; // Armazenar o resultado
private String Driver = "com.mysql.cj.jdbc.Driver"; // Identificar o banco de dados
private String caminho = "jdbc:mysql://ip:3306/horarios"; // caminho do bd
private String user = "root"; // usuario para acesso ao bd
private String senha = ""; // senha para acesso ao bd
public Connection conn; // Realiza conexão
public Connection getConnection() {
try {
Class.forName(Driver);
conn = DriverManager.getConnection(caminho, user, senha);// Define a url de conexão
Log.i(TAG, "Conexão: conectado");
return conn;
} catch (SQLException | ClassNotFoundException ex) {
return (Connection) ex;
}
}
I saw many talking to put the Activity in the manifest, but it is already there.
Androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tcc">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Please someone help me, I’m making this app for my tcc and the connection to mysql has to be made...
Thank you in advance