APP terminates unexpectedly on smartphone

Asked

Viewed 44 times

1

Below is the code and the logs. I try to run, but always closes the app unexpectedly. It closes without showing the error image or inserts in the bank.

 package...

imports

public class Cadastro extends AppCompatActivity
{
    EditText txtNome, txtEmail, txtSenha, txtRepeteSenha;
    Button btnCadastrar;
    ProgressBar progressBar;
    ConnectionClass connectionClass;

    @Override
    protected void onCreate (Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cadastro);
        connectionClass = new ConnectionClass();
        txtNome = findViewById(R.id.name);
        txtEmail = findViewById(R.id.email);
        txtSenha = findViewById(R.id.senha);
        txtRepeteSenha = findViewById(R.id.key_again);
        btnCadastrar = findViewById(R.id.cadastrar);
        progressBar = findViewById(R.id.progressBar);

        btnCadastrar.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick (View v){
                salvarBanco();
            }
        });
    }

    public Connection connectionBD(){
        Connection connection = null;
        String url = "jdbc:jtds:sqlserver://meu_ip:1433;databaseName=meu_banco;user=meu_user_banco;password=minha_senha_banco;";
        try {
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);
            Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
            connection = DriverManager.getConnection(url);
            Log.e("Script", "teste");
            Toast.makeText(getApplicationContext(),"Sucesso!",Toast.LENGTH_SHORT).show();
        }catch (Exception e){
            Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_SHORT).show();
        }
        return connection;
    }

    public void salvarBanco(){
        String query = "INSERT INTO Usuario(email, nome, senha) VALUES(?,?,?)";
        try{
            PreparedStatement preparedStatement = connectionBD().prepareStatement(query);
            preparedStatement.setString(1,txtEmail.getText().toString());
            preparedStatement.setString(2,txtNome.getText().toString());
            preparedStatement.setString(3,txtSenha.getText().toString());
            preparedStatement.executeUpdate();
        }catch (Exception e){
            Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_SHORT).show();
        }
    }
}

The mistake:

10-03 17:13:42.954 27329-27329/com.example.paulo.apptecnico E/AndroidRuntime: FATAL EXCEPTION: main
        Process: com.example.paulo.apptecnico, PID: 27329
        java.lang.VerifyError: net/sourceforge/jtds/jdbc/TdsCore
            at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:359)
            at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)
            at java.sql.DriverManager.getConnection(DriverManager.java:179)
            at java.sql.DriverManager.getConnection(DriverManager.java:144)
            at com.example.paulo.apptecnico.Cadastro.connectionBD(Cadastro.java:55)
            at com.example.paulo.apptecnico.Cadastro.salvarBanco(Cadastro.java:67)
            at com.example.paulo.apptecnico.Cadastro$1.onClick(Cadastro.java:41)
            at android.view.View.performClick(View.java:4740)
            at android.view.View$PerformClick.run(View.java:19383)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5679)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
            at dalvik.system.NativeStart.main(Native Method)
    10-03 17:13:43.284 853-27985/? E/android.os.Debug: !@Dumpstate > sdumpstate -k -t -z -d -o /data/log/dumpstate_app_error
    10-03 17:13:44.904 853-969/? E/ViewRootImpl: sendUserActionEvent() mView == null
    10-03 17:13:45.014 240-240/? E/SMD: DCD ON
    10-03 17:13:45.134 28010-28010/com.example.paulo.apptecnico E/dalvikvm: Could not find class 'android.support.v4.view.ViewCompat$OnUnhandledKeyEventListenerWrapper', referenced from method android.support.v4.view.ViewCompat.addOnUnhandledKeyEventListener
    10-03 17:13:45.134 28010-28010/com.example.paulo.apptecnico E/dalvikvm: Could not find class 'android.view.WindowInsets', referenced from method android.support.v4.view.ViewCompat.dispatchApplyWindowInsets
    10-03 17:13:45.144 28010-28010/com.example.paulo.apptecnico E/dalvikvm: Could not find class 'android.view.WindowInsets', referenced from method android.support.v4.view.ViewCompat.onApplyWindowInsets
    10-03 17:13:45.144 28010-28010/com.example.paulo.apptecnico E/dalvikvm: Could not find class 'android.view.View$OnUnhandledKeyEventListener', referenced from method android.support.v4.view.ViewCompat.removeOnUnhandledKeyEventListener
    10-03 17:13:45.144 28010-28010/com.example.paulo.apptecnico E/dalvikvm: Could not find class 'android.support.v4.view.ViewCompat$1', referenced from method android.support.v4.view.ViewCompat.setOnApplyWindowInsetsListener
    10-03 17:13:45.454 28010-28010/com.example.paulo.apptecnico E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
    10-03 17:13:45.454 28010-28010/com.example.paulo.apptecnico E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length

I switched to connection via connector, built with PHP and Volley, but not even send, because it closes the application as soon as I press the send button.

  • 1

    your problem is related to android version you are using, see the last lines of your error. as the Could not find class 'android.support.v4.view.ViewCompat$1', there are several identical errors with the same error and you can come up with a solution for them.

  • What should I do. which version should I migrate to? What I have here is Android Studio 3.2, Build #AI-181.5540.7.32.5014246, built on September 17, 2018, JRE: 1.8.0_152-release-1136-B06 amd64, JVM: Openjdk 64-Bit Server VM by Jetbrains s.r.o, Windows 10 10.0

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.