How can I Debug my app in real time?

Hi, people :wave: ;

My app runs well when I try in simulation, but when I’m using it in real time (without the computer), sometimes it crashes and I can’t figure out why…

I’d like to create a .txt or something in the try/catch to see where the error can be appearing (and later check that .txt to find the error).

Someone knows how to do it? or how can I see the error?

Aquaris M10 4G
Android version: 6.0

Thanks in advice :hugs:

I’ve a problem with that as well, because often even try/catch doen’t show the error in the console while crashing. I’ve tried to save the error/parameters as text, but it also didn’t work because the app crashed before catching. Saving can at least show until where the code did work properly, but it takes a considerable time and slows down the whole flow.
So I don’t have an answer but I solely respond because I don’t want The topic to die

1 Like

Thanks @noel, I couldn’t even generate the .txt :sweat_smile::sweat_smile: , or maybe I generate it but don’t find…

Can you tell me or show me how to do it?

I tried things like this:

try {
        FileWriter file = new FileWriter(getFileStreamPath("notas.txt"), true);
        file.write( "TRYING" );
        file.flush();
        file.close();
    } catch (IOException e) {}

or this:

        try {
            String rute = "/storage/emulated/0/DCIM/filename.txt";
            String content = "Example content";
            File file = new File(rute);
            if (!file.exists()) {
                file.createNewFile();
            }
            FileWriter fw = new FileWriter(file);
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write(content);
            bw.close();
        } catch (Exception e) {
            e.printStackTrace();
       }

In the first one I don’t know where is created, I managed to print the path but even with the path of the file I couldn’t access or find it :sweat_smile:

In the second one, I didn’t have permissions or something similar :sweat: (checked if is easily solvable and thought there have to be an easier way)

I use it this way. This time the file will be written, but sometimes it doesn’t make it to the catch block.
Later on I will try to get your method working.

//  !! Don't forget to give read/write permission !!

import android.os.Environment;
String path = new String(Environment.getExternalStorageDirectory().getAbsolutePath());
String[] my_parameters = new String[2]; 

// Do not write the parameters in try block
my_parameters[0] = "parameter a";
my_parameters[1] = "parameter b";

try {
  int z = 5/0;
} 
catch (Exception e) { 
  saveStrings(path+"/myErrorsLog.txt", my_parameters);
  e.printStackTrace();
}
1 Like