0

I have created a app for addition of two numbers but due to some uncertain error it crashes every time I click Add button for addition

I have checked my string resources and every thing but it is not solving

and please tell me what is these libmigui.so file as it is not opening(reference: logcat)

here is my XML file

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:background="#C6F36C6C"
    tools:context=".MainActivity">

    <EditText
        android:id="@+id/editTextNumber2"
        android:layout_width="265dp"
        android:layout_height="64dp"
        android:autofillHints="0"
        android:ems="10"
        android:inputType="number"
        android:textAlignment="center"
        android:textColor="#000000"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.493"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.325"
        tools:ignore="LabelFor,SpeakableTextPresentCheck,DuplicateSpeakableTextCheck,TextContrastCheck" />

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        tools:ignore="MissingConstraints" />

    <EditText
        android:id="@+id/editTextNumber"
        android:layout_width="268dp"
        android:layout_height="53dp"
        android:autofillHints=""
        android:inputType="number"
        android:textAlignment="center"
        android:textColor="@color/black"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.195"
        tools:ignore="LabelFor,SpeakableTextPresentCheck,TextContrastCheck" />

    <Button
        android:id="@+id/button"
        android:layout_width="131dp"
        android:layout_height="84dp"
        android:layout_marginBottom="276dp"
        android:background="@drawable/cylinder_button"
        android:text="@string/Add"
        android:textAllCaps="false"
        android:textColor="#EF6262"
        android:textSize="28sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/editTextNumber2"
        app:layout_constraintVertical_bias="1.0"
        tools:ignore="TextContrastCheck,TextSizeCheck" />

    <TextView
        android:id="@+id/OutPut"
        android:layout_width="340dp"
        android:layout_height="52dp"
        android:gravity="center"
        android:textSize="16sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.492"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button"
        app:layout_constraintVertical_bias="0.446"
        tools:ignore="TextContrastCheck" />

</androidx.constraintlayout.widget.ConstraintLayout>

here is MainActivity file

package com.example.calculator;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
    Button button;
    EditText tv , tv2;
    TextView OutPut;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button = findViewById(R.id.button);
        tv = findViewById(R.id.editTextNumber);
        tv2 = findViewById(R.id.editTextNumber2);
        OutPut = findViewById(R.id.OutPut);
        button.setOnClickListener((View v) -> {
            String s = tv.getText().toString();
            String s2 = tv2.getText().toString();
            int is = 0;
            is = Integer.parseInt(s);
            int is2 = 0;
            is2 = Integer.parseInt(s2);
            int output = 1234;
            OutPut.setText(output);
            Toast.makeText(MainActivity.this, "Addition Done !", Toast.LENGTH_SHORT).show();

        });


    }
}

here are logcats

2023-07-29 19:23:18.856 26102-26367 AdrenoGLES-0            com.example.calculator               I  Build Config                     : S P 10.0.7 AArch64
2023-07-29 19:23:18.856 26102-26367 AdrenoGLES-0            com.example.calculator               I  Driver Path                      : /vendor/lib64/egl/libGLESv2_adreno.so
2023-07-29 19:23:18.872 26102-26367 AdrenoGLES-0            com.example.calculator               I  PFP: 0x016ee190, ME: 0x00000000
2023-07-29 19:23:18.894 26102-26367 hw-ProcessState         com.example.calculator               D  Binder ioctl to enable oneway spam detection failed: Invalid argument
2023-07-29 19:23:18.918 26102-26102 libc                    com.example.calculator               I  Requested dump for tid 26102 (mple.calculator)
2023-07-29 19:23:19.170 26102-26367 mple.calculato          com.example.calculator               E  open libmigui.so failed! dlopen - dlopen failed: library "libmigui.so" not found
2023-07-29 19:23:19.174 26102-26102 Looper                  com.example.calculator               W  PerfMonitor doFrame : time=350ms vsyncFrame=0 latency=1ms procState=-1 historyMsgCount=1 (msgIndex=1 wall=350ms seq=14 running=36ms runnable=2ms io=3ms late=1ms h=android.view.Choreographer$FrameHandler c=android.view.Choreographer$FrameDisplayEventReceiver)
2023-07-29 19:23:19.179 26102-26102 Looper                  com.example.calculator               W  PerfMonitor doFrame : time=5ms vsyncFrame=0 latency=346ms procState=-1 historyMsgCount=4
2023-07-29 19:23:19.188 26102-26102 DecorView[]             com.example.calculator               D  onWindowFocusChanged hasWindowFocus true
2023-07-29 19:23:21.308 26102-26102 Compatibil...geReporter com.example.calculator               D  Compat change id reported: 163400105; UID 10447; state: ENABLED
2023-07-29 19:23:21.309 26102-26102 InputMethodManager      com.example.calculator               D  showSoftInput() view=androidx.appcompat.widget.AppCompatEditText{6f95288 VFED..CL. .F.P..ID 172,422-909,568 #7f0800ae app:id/editTextNumber aid=1073741825} flags=0 reason=SHOW_SOFT_INPUT
2023-07-29 19:23:21.319 26102-26102 AssistStructure         com.example.calculator               I  Flattened final assist data: 1592 bytes, containing 1 windows, 8 views
2023-07-29 19:23:21.493 26102-26102 InsetsController        com.example.calculator               D  show(ime(), fromIme=true)
2023-07-29 19:23:22.600 26102-26102 InputMethodManager      com.example.calculator               D  showSoftInput() view=androidx.appcompat.widget.AppCompatEditText{3f1b67a VFED..CL. .F.P..ID 173,693-902,869 #7f0800af app:id/editTextNumber2 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
2023-07-29 19:23:22.609 26102-26102 IInputConnectionWrapper com.example.calculator               W  requestCursorAnchorInfo on inactive InputConnection
2023-07-29 19:23:22.644 26102-26102 InsetsController        com.example.calculator               D  show(ime(), fromIme=true)
2023-07-29 19:23:22.672 26102-26102 InsetsController        com.example.calculator               D  show(ime(), fromIme=true)
2023-07-29 19:23:23.362 26102-26102 mple.calculato          com.example.calculator               E  Invalid ID 0x000004d2.
2023-07-29 19:23:23.363 26102-26102 AndroidRuntime          com.example.calculator               D  Shutting down VM
2023-07-29 19:23:23.365 26102-26102 AndroidRuntime          com.example.calculator               E  FATAL EXCEPTION: main
                                                                                                    Process: com.example.calculator, PID: 26102
                                                                                                    android.content.res.Resources$NotFoundException: String resource ID #0x4d2
                                                                                                        at android.content.res.Resources.getText(Resources.java:463)
                                                                                                        at android.content.res.MiuiResources.getText(MiuiResources.java:106)
                                                                                                        at android.widget.TextView.setText(TextView.java:6513)
                                                                                                        at com.example.calculator.MainActivity.lambda$onCreate$0$com-example-calculator-MainActivity(MainActivity.java:31)
                                                                                                        at com.example.calculator.MainActivity$$ExternalSyntheticLambda0.onClick(Unknown Source:2)
                                                                                                        at android.view.View.performClick(View.java:7745)
                                                                                                        at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1211)
                                                                                                        at android.view.View.performClickInternal(View.java:7722)
                                                                                                        at android.view.View.access$3700(View.java:854)
                                                                                                        at android.view.View$PerformClick.run(View.java:29111)
                                                                                                        at android.os.Handler.handleCallback(Handler.java:938)
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                                        at android.os.Looper.loopOnce(Looper.java:210)
                                                                                                        at android.os.Looper.loop(Looper.java:299)
                                                                                                        at android.app.ActivityThread.main(ActivityThread.java:8319)
                                                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                                                        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556)
                                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1038)
2023-07-29 19:23:23.361 26102-26102 mple.calculator         com.example.calculator               W  type=1400 audit(0.0:622224): avc: denied { search } for name="mqsas" dev="sda16" ino=208 scontext=u:r:untrusted_app:s0:c191,c257,c512,c768 tcontext=u:object_r:mqsas_data_file:s0 tclass=dir permissive=0 app=com.example.calculator
2023-07-29 19:23:23.374 26102-26102 OOMEventManagerFK       com.example.calculator               W  Failed to mkdir /data/mqsas/hprof/
2023-07-29 19:23:23.361 26102-26102 mple.calculator         com.example.calculator               W  type=1400 audit(0.0:622225): avc: denied { search } for name="mqsas" dev="sda16" ino=208 scontext=u:r:untrusted_app:s0:c191,c257,c512,c768 tcontext=u:object_r:mqsas_data_file:s0 tclass=dir permissive=0 app=com.example.calculator
2023-07-29 19:23:23.361 26102-26102 mple.calculator         com.example.calculator               W  type=1400 audit(0.0:622226): avc: denied { search } for name="mqsas" dev="sda16" ino=208 scontext=u:r:untrusted_app:s0:c191,c257,c512,c768 tcontext=u:object_r:mqsas_data_file:s0 tclass=dir permissive=0 app=com.example.calculator
2023-07-29 19:23:23.361 26102-26102 mple.calculator         com.example.calculator               W  type=1400 audit(0.0:622227): avc: denied { search } for name="mqsas" dev="sda16" ino=208 scontext=u:r:untrusted_app:s0:c191,c257,c512,c768 tcontext=u:object_r:mqsas_data_file:s0 tclass=dir permissive=0 app=com.example.calculator
2023-07-29 19:23:23.361 26102-26102 mple.calculator         com.example.calculator               W  type=1400 audit(0.0:622228): avc: denied { getattr } for path="/data/mqsas" dev="sda16" ino=208 scontext=u:r:untrusted_app:s0:c191,c257,c512,c768 tcontext=u:object_r:mqsas_data_file:s0 tclass=dir permissive=0 app=com.example.calculator
2023-07-29 19:23:23.417 26102-26102 Process                 com.example.calculator               I  Sending signal. PID: 26102 SIG: 9

RF1991
  • 2,037
  • 4
  • 8
  • 17

1 Answers1

0

Always check if getText() returns null, you can use TextUtils.isEmpty(string) for convenience.

Also, Integer.parseInt(string) may throw an exception, should be handled with something like this, or just show an error with a Toast.

public static int parseWithDefault(String number, int defaultVal) {
  try {
    return Integer.parseInt(number);
  } catch (NumberFormatException e) {
    return defaultVal;
  }
}

EDIT

Taking a closer look, it seems the actual issue is that you're using .setText(int), but that int refers to a resource id, not to a value you want to display.

int output = 1234;
OutPut.setText(output);

For displaying a value, it should always be a String. Use String.valueOf(…) to convert an item to its String representation.

int output = 1234;
OutPut.setText(String.valueOf(output));
cmak
  • 576
  • 1
  • 4
  • 15