Did my Android program crash because it lacks a delay mechanism?

In summary, the user modified code that originally displayed a toast when the screen was pressed and held. The code used onTouchListener with a relative layout, but the user changed it to a button instead. The user is having trouble understanding why the code is not working. The user is using Logcat to try and figure out what is wrong. The user is trying to update the GUI from a child thread, which will not work.
  • #1
Darkmisc
220
31
TL;DR Summary
I want to create a counter that increments while a button is held down, but it crashes when I click on it. Is it because I don't have a delay after each increment?
Hi everyone

I modified some code that originally displayed a toast when the screen was pressed and held. The original code used onTouchListener with a relative layout, but I changed it to a button instead. I think I've copied it correctly, but my program crashes when the button is clicked.

I figured I needed a delay after n++, but adding one doesn't seem to help.

Which part of my code have I messed up? Android Studio doesn't highlight any errors and the code is able to compile.

Thanks

Android Studio java:
package com.example.clickcounter;

import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    int n = 0;
    Button button;
    private Handler mHandler = new Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button = (Button) findViewById(R.id.button);
        TextView myText = (TextView) findViewById(R.id.textView);

        Runnable mRunnable = new Runnable(){
            public void run(){
                n++;
                myText.setText(n);
            }
        };

        button.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if(event.getAction() == MotionEvent.ACTION_DOWN){
                    mHandler.postDelayed(mRunnable, 100);     
                }
                return true;
            }
        });
    }
}
 
Last edited by a moderator:
Technology news on Phys.org
  • #2
Please post code inside [code=java][/code] tags, or use the </> button in the wysiwyg editor,

[Mentor Note -- code tags added to OP now]
 
Last edited by a moderator:
  • #3
Darkmisc said:
but my program crashes when the button is clicked
What Logcat error messages do you get when the crash takes place?
 
  • #4
Logcat:
2022-12-09 06:04:40.356 29896-29927/com.example.clickcounter D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 1 0

2022-12-09 06:04:46.820 29896-29896/com.example.clickcounter E/le.clickcounte: Invalid ID 0x00000001.

2022-12-09 06:04:46.821 29896-29896/com.example.clickcounter D/AndroidRuntime: Shutting down VM

2022-12-09 06:04:46.828 29896-29896/com.example.clickcounter E/AndroidRuntime: FATAL EXCEPTION: main

    Process: com.example.clickcounter, PID: 29896

    android.content.res.Resources$NotFoundException: String resource ID #0x1

        at android.content.res.Resources.getText(Resources.java:367)

        at android.widget.TextView.setText(TextView.java:6370)

        at com.example.clickcounter.MainActivity$1.run(MainActivity.java:31)

        at android.os.Handler.handleCallback(Handler.java:883)

        at android.os.Handler.dispatchMessage(Handler.java:100)

        at android.os.Looper.loop(Looper.java:214)

        at android.app.ActivityThread.main(ActivityThread.java:7356)

        at java.lang.reflect.Method.invoke(Native Method)

        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)

        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

2022-12-09 06:04:46.867 29896-29896/com.example.clickcounter I/Process: Sending signal. PID: 29896 SIG: 9
 
  • #5
TextView.setText has multiple signatures. In this case you are passing an integer, which is interpreted as a resource ID, but you do not have a text resource with that ID.

You can fix it if you convert the number to something that TextView.setText will interpret as a string instead.
 
  • Like
Likes Darkmisc and Wrichik Basu
  • #6
I like Serena said:
TextView.setText has multiple signatures. In this case you are passing an integer, which is interpreted as a resource ID, but you do not have a text resource with that ID.

You can fix it if you convert the number to something that TextView.setText will interpret as a string instead.
Thankfully, the OP posted here. At Stack Overflow, the OP would have received an overflow of votes. Guess which ones.

To the OP: The Logcat is your best friend in programming. Change myText.setText(n); to myText.setText(String.valueOf(n)); inside the thread.

Also, it is no longer necessary to explicitly type cast views. You can just do button = findViewById(R.id.button); nowadays.
 
  • Like
Likes Darkmisc
  • #7
Tell me something: is this code even working? Are you getting an update in the TextView? I have seen your next thread, which has similar code, but in Java Swing rather than Android. You are trying to update the GUI from a child thread. This will not work. Neither in Java nor in Android. GUI has to be updated from the main thread only.

In Android, we used to have an AsyncTask class. It was deprecated recently, so no use of talking about it.

Also, we ordinarily use OnClickListener rather than OnTouchListener on Android unless you really want to do something different when you receive MotionEvent.ACTION_UP. If you simply wish to increase your counter once and display it, use OnClickListener.

Increase the counter once and update TextView from child Thread:

Android:
final String MESSAGE_KEY_UPDATE_TEXT = "com.yourrganisation.yourapp.MSG_UPDATE_TEXT";

Handler handler = new Handler(Looper.getMainLooper()) {
   @Override
   public void handleMessage(@NonNull Message msg) {
        super.handleMessage(msg);
        // This is executed in main thread
        myText.setText(String.valueOf(msg.getData().getInt(MESSAGE_KEY_REQUEST_FOCUS));
   }
};final Thread thread = new Thread(() -> {
    Looper.prepare();

    // The delay after which you wanted to start the thread
    try {
        Thread.sleep(200);
    } catch (InterruptedException ignored) {}

    n++;

    Message message = Message.obtain();
    Bundle data = new Bundle();
    data.putInt(MESSAGE_KEY_UPDATE_TEXT, n);
    message.setData(data);
    handler.sendMessage(message);
});

button.setOnClickListener((view) -> {
   thread.start();  // Start the thread
});

Increase the counter as long as you keep the button pressed:

Android:
final String MESSAGE_KEY_UPDATE_TEXT = "com.yourrganisation.yourapp.MSG_UPDATE_TEXT";

AtomicBoolean stopThread = new AtomicBoolean(false);

Handler handler = new Handler(Looper.getMainLooper()) {
   @Override
   public void handleMessage(@NonNull Message msg) {
      super.handleMessage(msg);
      myText.setText(String.valueOf(msg.getData().getInt(MESSAGE_KEY_REQUEST_FOCUS));
   }
};

   final Thread thread = new Thread(() -> {

            Looper.prepare();

            // The delay after which you wanted to start the thread
            try {
                Thread.sleep(200);
            } catch (InterruptedException ignored) {}

            while (!stopThread.get()) {

                n++;

                Message message = Message.obtain();
                Bundle data = new Bundle();
                data.putInt(MESSAGE_KEY_UPDATE_TEXT, n);
                message.setData(data);
                handler.sendMessage(message);

                try {
                    Thread.sleep(100);
                } catch (InterruptedException ignored) {}
            }
        });

        button.setOnTouchListener((v, motionEvent) -> {

            switch (motionEvent.getAction()) {

                case MotionEvent.ACTION_DOWN:
                    stopThread.set(false);
                    thread.start();
                    return true;

                case MotionEvent.ACTION_UP:
                    // To stop the thread, you have to change this variable and wait for
                    // the loop to exit.
                    stopThread.set(true);
                    return true;

                default:
                    return false;
        }
});

Note that you cannot stop a thread by calling thread.stop(); Hence, we use an AtomicBoolean to get across this issue.
 
  • Like
Likes Darkmisc
  • #8
Wrichik Basu said:
Tell me something: is this code even working? Are you getting an update in the TextView? I have seen your next thread, which has similar code, but in Java Swing rather than Android. You are trying to update the GUI from a child thread. This will not work. Neither in Java nor in Android. GUI has to be updated from the main thread only.

In Android, we used to have an AsyncTask class. It was deprecated recently, so no use of talking about it.

Also, we ordinarily use OnClickListener rather than OnTouchListener on Android unless you really want to do something different when you receive MotionEvent.ACTION_UP. If you simply wish to increase your counter once and display it, use OnClickListener.

Increase the counter once and update TextView from child Thread:

Android:
final String MESSAGE_KEY_UPDATE_TEXT = "com.yourrganisation.yourapp.MSG_UPDATE_TEXT";

Handler handler = new Handler(Looper.getMainLooper()) {
   @Override
   public void handleMessage(@NonNull Message msg) {
        super.handleMessage(msg);
        // This is executed in main thread
        myText.setText(String.valueOf(msg.getData().getInt(MESSAGE_KEY_REQUEST_FOCUS));
   }
};final Thread thread = new Thread(() -> {
    Looper.prepare();

    // The delay after which you wanted to start the thread
    try {
        Thread.sleep(200);
    } catch (InterruptedException ignored) {}

    n++;

    Message message = Message.obtain();
    Bundle data = new Bundle();
    data.putInt(MESSAGE_KEY_UPDATE_TEXT, n);
    message.setData(data);
    handler.sendMessage(message);
});

button.setOnClickListener((view) -> {
   thread.start();  // Start the thread
});

Increase the counter as long as you keep the button pressed:

Android:
final String MESSAGE_KEY_UPDATE_TEXT = "com.yourrganisation.yourapp.MSG_UPDATE_TEXT";

AtomicBoolean stopThread = new AtomicBoolean(false);

Handler handler = new Handler(Looper.getMainLooper()) {
   @Override
   public void handleMessage(@NonNull Message msg) {
      super.handleMessage(msg);
      myText.setText(String.valueOf(msg.getData().getInt(MESSAGE_KEY_REQUEST_FOCUS));
   }
};

   final Thread thread = new Thread(() -> {

            Looper.prepare();

            // The delay after which you wanted to start the thread
            try {
                Thread.sleep(200);
            } catch (InterruptedException ignored) {}

            while (!stopThread.get()) {

                n++;

                Message message = Message.obtain();
                Bundle data = new Bundle();
                data.putInt(MESSAGE_KEY_UPDATE_TEXT, n);
                message.setData(data);
                handler.sendMessage(message);

                try {
                    Thread.sleep(100);
                } catch (InterruptedException ignored) {}
            }
        });

        button.setOnTouchListener((v, motionEvent) -> {

            switch (motionEvent.getAction()) {

                case MotionEvent.ACTION_DOWN:
                    stopThread.set(false);
                    thread.start();
                    return true;

                case MotionEvent.ACTION_UP:
                    // To stop the thread, you have to change this variable and wait for
                    // the loop to exit.
                    stopThread.set(true);
                    return true;

                default:
                    return false;
        }
});

Note that you cannot stop a thread by calling thread.stop(); Hence, we use an AtomicBoolean to get across this issue.
It only works as a regular click counter. That's when I realised I'd need some sort of loop. Thanks for the code. There are heaps of new topics in there that I wouldn't otherwise have known to look for.
 
  • #9
Darkmisc said:
It only works as a regular click counter.
In that case, don't use the OnTouchListener. Instead, use OnClickListener, as I have shown.
Darkmisc said:
That's when I realised I'd need some sort of loop.
What do you need a loop for? If you update the UI from a loop without any delay, Android will simply stop your application. If you do that from a background thread, make sure to add a delay, and a mechanism to stop the execution, as I have shown in the second code block.
Darkmisc said:
There are heaps of new topics in there that I wouldn't otherwise have known to look for.
It's better to start learning Android with a specific project in mind. Otherwise, you will not be able to grasp concepts like lifecycle, nor remember them.

We use a background thread to do IO operations, like reading a database. IO operations are time-consuming and can hold up the main thread and freeze UI elements, resulting in an ANR (App Not Responding error). The database is read and stored in a data structure, like a List or an ArrayList. When we need to populate the view (like RecyclerView), we use that list.
 
  • Like
Likes Darkmisc
  • #10
Wrichik Basu said:
In that case, don't use the OnTouchListener. Instead, use OnClickListener, as I have shown.

What do you need a loop for? If you update the UI from a loop without any delay, Android will simply stop your application. If you do that from a background thread, make sure to add a delay, and a mechanism to stop the execution, as I have shown in the second code block.

It's better to start learning Android with a specific project in mind. Otherwise, you will not be able to grasp concepts like lifecycle, nor remember them.

We use a background thread to do IO operations, like reading a database. IO operations are time-consuming and can hold up the main thread and freeze UI elements, resulting in an ANR (App Not Responding error). The database is read and stored in a data structure, like a List or an ArrayList. When we need to populate the view (like RecyclerView), we use that list.
I might have incorrectly used the term "loop" to describe repetition in general. I realised my code would only execute n++ once. That's why n only increased by one for each click (and hold).
 
  • #11
Have I cut and pasted the code into the wrong spot? I can't seem to get the code to run.

MESSAGE_KEY_REQUEST_FOCUS at line 39 gets highlighted in red. I tried creating a new MESSAGE_KEY_REQUEST_FOCUS variable and also setting the text to a simple string, just to see if it would run, but it didn't.

ClickCounter:
package com.example.clickcounter;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.util.concurrent.atomic.AtomicBoolean;

public class MainActivity extends AppCompatActivity {

    int n = 0;
    Button button;

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

        button = (Button) findViewById(R.id.button);
        TextView myText = (TextView) findViewById(R.id.textView);

        final String MESSAGE_KEY_UPDATE_TEXT = "com.yourrganisation.yourapp.MSG_UPDATE_TEXT";

        AtomicBoolean stopThread = new AtomicBoolean(false);

        Handler handler = new Handler(Looper.getMainLooper()) {
            @Override
            public void handleMessage(@NonNull Message msg) {
                super.handleMessage(msg);
                myText.setText(String.valueOf(msg.getData().getInt(MESSAGE_KEY_REQUEST_FOCUS)));
            }
        };

        final Thread thread = new Thread(() -> {

            Looper.prepare();

            // The delay after which you wanted to start the thread
            try {
                Thread.sleep(200);
            } catch (InterruptedException ignored) {}

            while (!stopThread.get()) {

                n++;

                Message message = Message.obtain();
                Bundle data = new Bundle();
                data.putInt(MESSAGE_KEY_UPDATE_TEXT, n);
                message.setData(data);
                handler.sendMessage(message);

                try {
                    Thread.sleep(100);
                } catch (InterruptedException ignored) {}
            }
        });

        button.setOnTouchListener((v, motionEvent) -> {

            switch (motionEvent.getAction()) {

                case MotionEvent.ACTION_DOWN:
                    stopThread.set(false);
                    thread.start();
                    return true;

                case MotionEvent.ACTION_UP:
                    // To stop the thread, you have to change this variable and wait for
                    // the loop to exit.
                    stopThread.set(true);
                    return true;

                default:
                    return false;
            }
        });

    }

}
This is the Logcat that I get

Logcat:
2022-12-09 08:46:07.990 30956-30991/com.example.clickcounter D/libEGL: Emulator has host GPU support, qemu.gles is set to 1.
2022-12-09 08:46:07.994 30956-30991/com.example.clickcounter W/libc: Unable to set property "qemu.gles" to "1": connection failed; errno=13 (Permission denied)
2022-12-09 08:46:07.978 30956-30956/com.example.clickcounter W/RenderThread: type=1400 audit(0.0:166): avc: denied { write } for name="property_service" dev="tmpfs" ino=8445 scontext=u:r:untrusted_app:s0:c136,c256,c512,c768 tcontext=u:object_r:property_socket:s0 tclass=sock_file permissive=0
2022-12-09 08:46:08.075 30956-30991/com.example.clickcounter D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
2022-12-09 08:46:08.086 30956-30991/com.example.clickcounter D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
2022-12-09 08:46:08.284 30956-30956/com.example.clickcounter W/le.clickcounte: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2022-12-09 08:46:08.286 30956-30956/com.example.clickcounter W/le.clickcounte: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2022-12-09 08:46:08.682 30956-30989/com.example.clickcounter D/HostConnection: HostConnection::get() New Host Connection established 0xd861fc30, tid 30989
2022-12-09 08:46:08.744 30956-30989/com.example.clickcounter D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_sync_buffer_data GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_2
2022-12-09 08:46:08.793 30956-30989/com.example.clickcounter W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2022-12-09 08:46:08.856 30956-30989/com.example.clickcounter D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 0 0
2022-12-09 08:46:08.856 30956-30989/com.example.clickcounter D/EGL_emulation: eglCreateContext: 0xeed7eda0: maj 2 min 0 rcv 2
2022-12-09 08:46:08.876 30956-30989/com.example.clickcounter D/EGL_emulation: eglMakeCurrent: 0xeed7eda0: ver 2 0 (tinfo 0xe3caa4f0)
2022-12-09 08:46:08.903 30956-30989/com.example.clickcounter W/Gralloc3: mapper 3.x is not supported
2022-12-09 08:46:08.919 30956-30989/com.example.clickcounter D/HostConnection: createUnique: call
2022-12-09 08:46:08.919 30956-30989/com.example.clickcounter D/HostConnection: HostConnection::get() New Host Connection established 0xd8621440, tid 30989
2022-12-09 08:46:08.971 30956-30989/com.example.clickcounter D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_sync_buffer_data GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_2
2022-12-09 08:46:08.974 30956-30989/com.example.clickcounter D/eglCodecCommon: allocate: Ask for block of size 0x1000
2022-12-09 08:46:08.974 30956-30989/com.example.clickcounter D/eglCodecCommon: allocate: ioctl allocate returned offset 0x3ffff6000 size 0x2000
2022-12-09 08:46:09.013 30956-30989/com.example.clickcounter D/EGL_emulation: eglMakeCurrent: 0xeed7eda0: ver 2 0 (tinfo 0xe3caa4f0)
2022-12-09 08:46:09.021 30956-30989/com.example.clickcounter D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 1 0
2022-12-09 08:46:09.321 30956-30956/com.example.clickcounter I/Choreographer: Skipped 42 frames!  The application may be doing too much work on its main thread.
2022-12-09 08:47:22.501 31077-31111/com.example.clickcounter D/libEGL: Emulator has host GPU support, qemu.gles is set to 1.
2022-12-09 08:47:22.488 31077-31077/com.example.clickcounter W/RenderThread: type=1400 audit(0.0:167): avc: denied { write } for name="property_service" dev="tmpfs" ino=8445 scontext=u:r:untrusted_app:s0:c136,c256,c512,c768 tcontext=u:object_r:property_socket:s0 tclass=sock_file permissive=0
2022-12-09 08:47:22.503 31077-31111/com.example.clickcounter W/libc: Unable to set property "qemu.gles" to "1": connection failed; errno=13 (Permission denied)
2022-12-09 08:47:22.584 31077-31111/com.example.clickcounter D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
2022-12-09 08:47:22.590 31077-31111/com.example.clickcounter D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
2022-12-09 08:47:22.596 31077-31111/com.example.clickcounter D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
2022-12-09 08:47:22.806 31077-31077/com.example.clickcounter W/le.clickcounte: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2022-12-09 08:47:22.806 31077-31077/com.example.clickcounter W/le.clickcounte: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2022-12-09 08:47:23.028 31077-31109/com.example.clickcounter D/HostConnection: HostConnection::get() New Host Connection established 0xdbc582d0, tid 31109
2022-12-09 08:47:23.061 31077-31109/com.example.clickcounter D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_sync_buffer_data GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_2
2022-12-09 08:47:23.078 31077-31109/com.example.clickcounter W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2022-12-09 08:47:23.115 31077-31109/com.example.clickcounter D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 0 0
2022-12-09 08:47:23.116 31077-31109/com.example.clickcounter D/EGL_emulation: eglCreateContext: 0xdbc1a120: maj 2 min 0 rcv 2
2022-12-09 08:47:23.126 31077-31109/com.example.clickcounter D/EGL_emulation: eglMakeCurrent: 0xdbc1a120: ver 2 0 (tinfo 0xdbc0f1e0)
2022-12-09 08:47:23.145 31077-31109/com.example.clickcounter W/Gralloc3: mapper 3.x is not supported
2022-12-09 08:47:23.151 31077-31109/com.example.clickcounter D/HostConnection: createUnique: call
2022-12-09 08:47:23.152 31077-31109/com.example.clickcounter D/HostConnection: HostConnection::get() New Host Connection established 0xdbc58410, tid 31109
2022-12-09 08:47:23.164 31077-31109/com.example.clickcounter D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_sync_buffer_data GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_2
2022-12-09 08:47:23.166 31077-31109/com.example.clickcounter D/eglCodecCommon: allocate: Ask for block of size 0x1000
2022-12-09 08:47:23.166 31077-31109/com.example.clickcounter D/eglCodecCommon: allocate: ioctl allocate returned offset 0x3ffff6000 size 0x2000
2022-12-09 08:47:23.187 31077-31109/com.example.clickcounter D/EGL_emulation: eglMakeCurrent: 0xdbc1a120: ver 2 0 (tinfo 0xdbc0f1e0)
2022-12-09 08:47:23.193 31077-31109/com.example.clickcounter D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 1 0
2022-12-09 08:48:26.621 31195-31195/? I/le.clickcounte: Late-enabling -Xcheck:jni
2022-12-09 08:48:26.632 31195-31195/? E/le.clickcounte: Unknown bits set in runtime_flags: 0x8000
2022-12-09 08:48:26.632 31195-31195/? W/le.clickcounte: Unexpected CPU variant for X86 using defaults: x86
2022-12-09 08:48:27.231 31195-31229/com.example.clickcounter D/libEGL: Emulator has host GPU support, qemu.gles is set to 1.
2022-12-09 08:48:27.228 31195-31195/com.example.clickcounter W/RenderThread: type=1400 audit(0.0:168): avc: denied { write } for name="property_service" dev="tmpfs" ino=8445 scontext=u:r:untrusted_app:s0:c136,c256,c512,c768 tcontext=u:object_r:property_socket:s0 tclass=sock_file permissive=0
2022-12-09 08:48:27.236 31195-31229/com.example.clickcounter W/libc: Unable to set property "qemu.gles" to "1": connection failed; errno=13 (Permission denied)
2022-12-09 08:48:27.251 31195-31229/com.example.clickcounter D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
2022-12-09 08:48:27.255 31195-31229/com.example.clickcounter D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
2022-12-09 08:48:27.259 31195-31229/com.example.clickcounter D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
2022-12-09 08:48:27.433 31195-31195/com.example.clickcounter W/le.clickcounte: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2022-12-09 08:48:27.433 31195-31195/com.example.clickcounter W/le.clickcounte: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2022-12-09 08:48:27.653 31195-31227/com.example.clickcounter D/HostConnection: HostConnection::get() New Host Connection established 0xdbc76050, tid 31227
2022-12-09 08:48:27.678 31195-31227/com.example.clickcounter D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_sync_buffer_data GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_2
2022-12-09 08:48:27.684 31195-31227/com.example.clickcounter W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2022-12-09 08:48:27.723 31195-31227/com.example.clickcounter D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 0 0
2022-12-09 08:48:27.723 31195-31227/com.example.clickcounter D/EGL_emulation: eglCreateContext: 0xdbc1a120: maj 2 min 0 rcv 2
2022-12-09 08:48:27.734 31195-31227/com.example.clickcounter D/EGL_emulation: eglMakeCurrent: 0xdbc1a120: ver 2 0 (tinfo 0xdbc0f1e0)
2022-12-09 08:48:27.744 31195-31227/com.example.clickcounter W/Gralloc3: mapper 3.x is not supported
2022-12-09 08:48:27.746 31195-31227/com.example.clickcounter D/HostConnection: createUnique: call
2022-12-09 08:48:27.746 31195-31227/com.example.clickcounter D/HostConnection: HostConnection::get() New Host Connection established 0xdbc762d0, tid 31227
2022-12-09 08:48:27.747 31195-31227/com.example.clickcounter D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_sync_buffer_data GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_2
2022-12-09 08:48:27.749 31195-31227/com.example.clickcounter D/eglCodecCommon: allocate: Ask for block of size 0x1000
2022-12-09 08:48:27.749 31195-31227/com.example.clickcounter D/eglCodecCommon: allocate: ioctl allocate returned offset 0x3ffff6000 size 0x2000
2022-12-09 08:48:27.806 31195-31227/com.example.clickcounter D/EGL_emulation: eglMakeCurrent: 0xdbc1a120: ver 2 0 (tinfo 0xdbc0f1e0)
2022-12-09 08:48:27.812 31195-31227/com.example.clickcounter D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 1 0
 
  • #12
Darkmisc said:
MESSAGE_KEY_REQUEST_FOCUS at line 39 gets highlighted in red.
My bad. I copied the code from one of my repos, forgot to make all changes. Change line 39 to:
Android:
myText.setText(String.valueOf(msg.getData().getInt(MESSAGE_KEY_UPDATE_TEXT)));
Essentially, the same variable as in line 31.
 
  • Like
Likes Darkmisc

FAQ: Did my Android program crash because it lacks a delay mechanism?

Why do Android programs sometimes crash?

Android programs can crash for various reasons, such as coding errors, memory leaks, or compatibility issues. However, one common cause is the lack of a delay mechanism in the code.

How does a delay mechanism prevent crashes?

A delay mechanism allows for a pause in the execution of the program, giving time for the system to process and complete tasks before moving on to the next instruction. Without a delay mechanism, the program may attempt to execute tasks simultaneously, leading to crashes.

Can the lack of a delay mechanism be the sole reason for crashes?

No, the lack of a delay mechanism is not the only reason for crashes. As mentioned earlier, there can be multiple factors that contribute to a program crashing, and it is essential to thoroughly troubleshoot and identify the root cause.

How can I add a delay mechanism to my Android program?

There are various ways to add a delay mechanism to an Android program, depending on the programming language and development environment being used. For example, in Java, you can use the Thread.sleep() method to pause the execution for a specified amount of time.

Are there any alternatives to a delay mechanism to prevent crashes?

Yes, there are other techniques that can be used to prevent crashes, such as implementing proper exception handling, optimizing code for memory usage, and testing the program on different devices and operating systems. It is always recommended to follow good coding practices and thoroughly test the program to ensure its stability.

Similar threads

Back
Top