-2
Good afternoon, I’m having a problem and can’t solve it. Every time I try to test the app on the phone it closes alone:
Logcat: 2020-05-09 16:02:58.397 30691-30691/com.leandrel.Uri E/Androidruntime: FATAL EXCEPTION: main Process: com.leandrel.Uri, PID: 30691 java.lang.Illegalstateexception: Could not execute method for android:onClick at androidx.appcompat.app.Appcompatviewinflater$Declaredonclicklistener.onClick(Appcompatviewinflater.java:390) at android.view.View.performClick(View.java:6608) at android.view.View.performClickInternal(View.java:6585) at android.view.View.access$3100(View.java:785) at android.view.View$Performclick.run(View.java:25921) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:201) at android.app.Activitythread.main(Activitythread.java:6810) at java.lang.reflect.Method.invoke(Native Method) at com.android.Internal.os.Runtimeinit$Methodandargscaller.run(Runtimeinit.java:547) at com.android.Internal.os.Zygoteinit.main(Zygoteinit.java:873) Caused by: java.lang.reflect.Invocationtargetexception at java.lang.reflect.Method.invoke(Native Method) at androidx.appcompatcompat.app.Appcompatviewinflater$Declaredonclicklistener.onClick(Appcompatviewinflater.java:385) at android.view.View.performClick(View.java:6608) at android.view.View.performClickInternal(View.java:6585) at android.view.View.access$3100(View.java:785) at android.view.View$Performclick.run(View.java:25921) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:201) at android.app.Activitythread.main(Activitythread.java:6810) at java.lang.reflect.Method.invoke(Native Method) at com.android.Internal.os.Runtimeinit$Methodandargscaller.run(Runtimeinit.java:547) at com.android.Internal.os.Zygoteinit.main(Zygoteinit.java:873) Caused by: java.lang.Numberformatexception: For input string: "androidx.appcompatcompat.widget.Appcompatedittext{d676bdc VFED. .CL. .F..... 552,916-901,1092 #7f070037 app:id/edtNmr}" at java.lang.Integer.parseint(Integer.java:615) at java.lang.Integer.parseint(Integer.java:650) at com.leandrel.Uri.MainActivity.verificar(Mainactivity.java:23) at java.lang.reflect.Method.invoke(Native Method) at androidx.appcompatcompat.app.Appcompatviewinflater$Declaredonclicklistener.onClick(Appcompatviewinflater.java:385) at android.view.View.performClick(View.java:6608) at android.view.View.performClickInternal(View.java:6585) at android.view.View.access$3100(View.java:785) at android.view.View$Performclick.run(View.java:25921) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:201) at android.app.Activitythread.main(Activitythread.java:6810) at java.lang.reflect.Method.invoke(Native Method) at com.android.Internal.os.Runtimeinit$Methodandargscaller.run(Runtimeinit.java:547) at com.android.Internal.os.Zygoteinit.main(Zygoteinit.java:873) 2020-05-09 16:02:58.476 30691-30691/com.leandrel.Uri I/Process: Sending Signal. PID: 30691 SIG: 9
The code in Java:
package com.leandrel.uri;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText nmr = findViewById(R.id.edtNmr);
}
public void verificar(View view) {
EditText nmr = findViewById(R.id.edtNmr);
String conv = String.valueOf(nmr);
int inteiro = Integer.parseInt(conv);
int i = 0, soma = 0;
TextView result = findViewById(R.id.txvResult);
for(i=1;i<inteiro;i++){
if(i%inteiro==0){
soma += i;
}
}
if(soma==inteiro){
result.setText("O número "+inteiro+" é perfeito");
}else{
result.setText("O número "+inteiro+" não é perfeito");
}
}
}