Logcat not displaying my log calls - android

I'm a total noob at Android programming, and wanted to learn how to debug my apps. I can't seem to have my Log.i|d|v calls displayed in the LogCat.
Here's the code that I'm using. As you can see I have defined a LOG_TAG constant, but can't seem to find it in the LogCat. I have also imported android.util.Log AND I have made sure that in my AndroidManifest I have "debuggable" set to TRUE.
I have also checked http://developer.android.com/reference/android/util/Log.html w/o any luck resolving this issue.
What am I doing wrong? Am I even looking in the right place? I've tried using the DDMS and Debug perspective as well w/o any luck. Any help to this noob would be greatly appreciated. Thanks.
My environment:
Windows XP
IDE = Eclipse Version: 3.6.1, Build id: M20100909-0800
Emulator = having it point to android sdk 2.1 api 7
//very basic HELLO World code with a couple of Log.i calls
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class debugger extends Activity {
private static final String LOG_TAG = "debugger";
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
Log.i(LOG_TAG, "line 13");
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.i(LOG_TAG, "CREATING NOW");
}
}

When using Eclipse, in the DDMS perspective, make sure the correct device (propably emulator-xxxx) is selected and highlighted. Only then will you get the logcat output in the logcat view.
Also, the Android plugin is a bit quircky, and sometimes only shows the last line in the logcat view. If this happens, try to clear the log. After that, you should get all the log entries again (works for me anyway).

If all else fails:
I did all the above things and couldn't figure out what was wrong,
Test with:
adb logcat
to figure out that my entries were infact in logcat, but twas adt's quirks.
Fix:
Restart eclipse
This was the only thing that fixed it.

I've had the same problem using Android Studio and managed to get around by selecting No Filters in the select box in the top right corner of LogCat. By doing this I started receiving everything Android logs in the background into LogCat including my missing Log calls.

Restart Eclipse and check log cat will be displayed.

I figured out I was automatically importing com.sileria.Log (from some library project) instead of android.util.Log, where the latter was the correct one. Check your imports as well.

I've noticed that Eclipse will sometimes throw an exception upon starting an Android app, then LogCat stops updating. I've corrected that by simply restarting Eclipse. I'm not sure if you've tried that and I know it's far from an optimal solution, but I suspect that the Eclipse plugin still has a few bugs to iron out.

Easiest way:
Check in your logcat window - TOP RIGHT corner PAUSE button || (Pause receiving new logcat messages)
Few clicks + eventually restart eclipse (usually works in my case)

I needed to restart the adb service with the command adb usb
Prior to this I was getting all logging and able to debug, but wasn't getting my own log lines (yes, I was getting system logging associated with my application).

There are a number of reasons why you might not see logs, most of which are listed below. Here are some steps to check most reasons:
Make sure you don't have 'android:debuggable="false"' in your
AndroidManifest.xml
Make sure your logcat isn't paused and make sure you are scrolled to the bottom
Your filters should either be 'no filters' or your current app
You have the correct device selected in your logcat devices list
If you're not getting any messages, try restarting adb. You can do that from Android Studio by clicking on the 'restart' icon, it's right after the print icon for logcat and it looks like a green curved arrow coming out of a box. If you don't see it, mouse over the '>>' that continues the icon menu when the logcat is too small.

QUICK FIX.
Just restart the eclipse
Works Perfect.

On Android Studio:
Click on the green arrow pointing to the right to restart the logging; if it is not visible, click on the >> icons to locate it.

I'm a newb as well to Android-Eclipse. Here's what it took for me to get LogCat messages to display in Eclipse:
1: add this to the class in which the logcat message is called:
private static final String TAG = "MyActivity"; (per the documentation here)
2: add this Log.i(TAG, "inLayout - finished"); when you where you want to display a message
If the above doesn't work, then shutdonw Eclipse and restart it and rerun your project.
It should then work.

There is one more thing to watch for:
On the top right side of the logcat there is a dropdown table for filtering messages by type. Make sure it's on the level you are looking for (if it will be on the assert level, it will likely leave your logcat empty).

Please go to Task Manager and kill the adb.exe process. Restart your eclipse again.
or
try adb kill-server and then adb start-server command.

Probably it's not be correct, and a little bit longer, but I solved this problem (Android Studio) by using this:
System.out.println("Some text here");
Like this:
try {
...code here...
} catch(Exception e) {
System.out.println("Error desc: " + e.getMessage());
}

I spent several hours on such case. I saw only touch keys logs. Nothing more. Problem was... smarthphone. After restarting was OK. Disconnecting cable caused problem returned. Had to restart it again.
Looks like the Android USB communication is not well designed.

Using the SDK 4.0.3 you have to explicitly select it on debug configurations > project > target or else it will never show using Eclipse Indigo (3.7). Of course an eclipse restart ensues.

I had a problem seeing simple log output in logcat as well. My problem was solved when I installed the latest JDK. I just setup a new development machine and only had the JRE installed and instaling the JDK worked for me.

None of the other answers worked for me, but this did:
I removed my project from my workspace, then deleted anything that started with a dot (.settings, .project, etc.) from the project folder. Then I re-imported the projected. I'm missing some settings and breakpoints but at least it works.

I had been experiencing this problem and nothing seemed to work until I moved the log call into a handler. Now it works every time, no matter where you are at.

I made the mistake of typing in a search term in the logcat search box.
I forgot to delete it and hence couldn't see the new logs. Since they didn't match my search term and weren't displayed.

In my case, I had to remove this line:
<application
android:debuggable="false" <!-- Remove this line -->
..../>
From Application tag in my Manifest file.

Best solution for me was restart adb server (while I have Enabled ADB integration in Android studio - Tools - Android - checked). To do this quickly I created adbr.bat file inside android-sdk\platform-tools directory (where is adb.exe located) with this inside:
adb kill-server
adb start-server
Because I have this folder in PATH system variable, always when I need restart adb from Android studio, I can write only into terminal adbr and it is done.
Another option to do this is through Android Device Monitor in Devices tab - Menu after click on small arrow right - Reset adb.

For eclipse:
1) Go to ddms perspective.
2) Make sure that correct device is selected.
3) If already selected and not displaying logs, then restart ABD.
* Hope this will solve.

I restarted the ADB service as well with "adb usb" and fixes the problem for me. In fact, only one of my activities didn't log anymore. All the others did log stuff. After restart adb everything works like a charm again. For the other people who're searching for another solution: adb kill-server, adb start-server in CLI will often fix your problem aswell.

make your app force close once
this will start LogCat again ...
use this for force close :D
setContentView(BIND_AUTO_CREATE);

some times the problem is not from pc on the other hand IDE,ADB etc, but it arises from your device that doesn't send logs to ADB so if you tried all the ways mentioned before and still your logcat is empty try to restart your device and try again.I tried all the ways mentioned above and neither of them worked but after a restart on my phone logcat worked like magic

I have this problems and fixed, String TAG without space:
"my tag" // noting show
"my_tag" // is ok

In my case I just had to add a name to the String. In first instance I just had a space in between the brackets
private static final String TAG = " ";
but after adding a name it worked perfectly.
private static final String TAG = "oncreate";

After upgrade to Android 3.6.1, I have experienced this issue multiple times.
The only thing that works in my case is RESTARTING THE DEVICE.

Related

Android Studio, logcat cleans after app closes

I'm having a problem with my logcat since update 1.2 Beta for Android Studio. When I run my app it logs everything like it normally did, then I get at the point where my app crashes with the app saying: unfortunately, Game has stopped.
After a few seconds android closes that message. When that happens my logcat also gets fully cleared meaning that I barely get anytime to read the error. I did found some info about a buffer, but it seems that Android Studio doesn't have the option to increase it besides the fact that I doubt that being the problem.
Something that may be useful is that after it clears and stuff the process changes to Android.process.core and the message I get in my logcat is:
04-13 10:28:13.394 12259-12265/android.process.acore D/dalvikvm﹕
Debugger has detached; object registry had 1 entries
Edit: I did read about breakpoints, so disabled focus application on breakpoints in Settings-build, execution, deployment-debugger but it didn't have any effect.
I had the same issue, but looks more like a feature than a bug:
In AndroidStudio, the default setting for the Logcat window seems to be "Show only selected Application" (top right corner of the Logcat window)... which is looking at the log of the selected process (your current launch by default). So when your app crashes during testing, that process is gone, so the filter clears the log.
Instead, select "Edit Filter Configuration..." and set up a filter for your app, eg:
FilterName: MyApp
PackageName: com.example.myapp (<< replace with your app's package name)
...and then select that filter for future runs. This should keep the log there for you, even after the app crashes.
Switch "Show only selected application" to "No filters". This way, you can see logcat output from a process even when that process isn't running.
The downside is that your logcat will be filled with more spam from other processes.
In case of crash see the Run tab at the bottom of IDE.
You can see the crash reason in this part (even in logcat clean case).
Note: If the above trick not works try to produce a crash and immediately disconnect the mobile cable (if you use the real device for the test). you can see the error before it cleaned.
Update: If also above trick not works, try to attach and detach phone and hopefully problem solved.
Update2: If again not work, try to Invalidate catches and Restart then start debugging again.
Update3: As The last way, try to remove the app and install it again then start debugging (if you do not lose that condition you want to test)
My App was crashing and restarting. I also had some problems on reading the logcat to know what was happening. I then noticed that in the drop down menu, next to the Device dropdown it had something like "com.mypackage.myapp ('some number')" and when my app crashed there was another option that said "com.mypackage.myapp ('some number') [DEAD]". If you select the "Dead" option, it will show you the logcat of the previous instance.
Might be very late to the party but I had the same problem and solved like this:
In logcat window, top right corner drop-down menu select Edit filter configuration, on the next menu, introduce Filter name and your Package name.
Done, for me it keeps logs visible after crashing.
In Android Studio 2+
Click Run
Click Edit Configurations
In the Run/Debug Configurations window select the Miscellaneous tab
Make sure the Clear log before launch checkbox is not checked
The filter clears the log once the app gets crashed. So select "Edit Filter Configuration" and create your own custom filter with filter name. This will save the log with informations even when the app is crahed.
I'm Working with Android Studio 4.0
enter image description here
Go to Edit Configuration of your app.
Go to Miscellaneous Tab
Uncheck the field Clear log before launch.
Press OK.
It'll work..
i have faced the same issue and this is the solution :-
1- Tools --> Android --> Enable ADB Integration.
and now you can see the logcat and the crashes as normal
It is 2018 and this can still happen. Close Android Studio and reopen.
7 years later ...
I still have same issue on AS ArcticFox and nothing helps.
But I have found one workaround.
make sure this is enabled:
Then you can see your logs regardless the app is alive or not or device is connected or not. Which is great!
Still, sometimes I get this problem although some solutions work here such as restarting android studio it takes time.
Here I found how to get error message without restarting the studio
Launch the app
Be on run tab before you make your reproduce crash
Click on the content of run tab as soon as crash occurs (if you don't click on content you will lose error report)
This bug seems to be fixed with the new release of Android Studio version 1.2.2
I ran into the same problem and none of the answers could help me, until I realized my app was causing an OutOfMemoryException. That's a probable root cause as well.

Debugging Genymotion in Eclipse on Windows 7

I've been using the Genymotion Android emulator for 2 weeks now. So far all was good, I was able to debug and everything was working fine (and in a pretty fast way too).
Suddenly the debugger went crazy yesterday: it jumps over certain lines of code, does not execute certain methods, shows that an obj instance is not null (on mouse over) but does not execute if (obj != null) code blocks which follow, etc. etc.
Is there any solution for this?
In fact, I think it's behaving the same way with the standard Android emulator too. And that also started yesterday. So I am just puzzled what I can do in order to fix this weird problem and continue working normally.
Needless to say I cleaned and rebuilt my project a few times in Eclipse. Rebooted my PC too. Nothing helps for now.
I can't be sure that this is the issue, but I have experienced a weird debugging behavior when I had an interface with two method with the same generic type name but different signatures, e.g.:
public <T extends Something1> void method1(T t){...}
public <T extends Something2> void method2(T t){...}
The issues I've encountered were:
I could not evaluate any expression.
Count not step in or over, only run... till the next breakpoint.
I'm sure there were other things but I've looked over them as I was only trying to get things done :|
For some reason this is known issue in Eclipse and has not been resolved for the last few years...
So the real solution for this is actually to rename one (or both) of the generic param names to so:
public <T1 extends Something1> void method1(T1 t){...}
public <T2 extends Something2> void method2(T2 t){...}
Surprisingly this solved the bug for me which drove me nuts for a real long time!
I hope this is the issue :)
this could be not related to the emulator then
as standard emulator is not working fine too.
this could be some miss-sync between the source code and the compilation result
so the debugger starts acting crazy
i had this one time,
the sol was related to the option add line number attributes to generated class files (used by the debugger)
to find that option:
1- right click on the project you have trouble with
2- select properties
3- from left pane, select java Compiler
4- at lower part of right pane, under Classfile Generation:
here you may have 2 cases:
1- that option is NOT checked, so just check it, click apply, and a clean-build might be good
2- if that option is CHECKED, the uncheck it, click apply, close the dialog, clean the project, and buil.
THEN re-open the dialog and navigate to that option, CHECK it, click apply, then close dialog
clean project and build.
Note: it might be better while doing this to unselect Build Automatically option from Window menu
then re-enable it once you have done above steps.
good luck

Why is logcat not showing anything? [duplicate]

This question already has answers here:
Why doesn't logcat show anything in my Android?
(29 answers)
Closed 7 years ago.
I am using Eclipse classic to develop my Android applications. But I am not able to see any messages in the LogCat. Till yesterday it was showing each and every message, but now it is not showing anything. I have written a lot of log statements to trace my program, but because of this I am not able to trace.
Where is the problem?
Try these first
Go to the device tab, click your device. and go back to the logcat
tab
You might have filter set.
You are probably viewing the wrong package.
I've got it solved by:
Closing the logcat window
Running the following in command prompt:
adb kill-server
adb start-server
Opening logcat again
Every now and then I experience that the logcat output in Eclipse stops showing any logs. It doesn't matter if I unplug and plug the device. It seems like the issue occurs if the logcat gets a ton of messages, and is unable to handle the amount.
The only thing working is restarting Eclipse or use DDMS directly (which also suffers from the same problem).
Go to Window - Preferences - Android - Logcat .
On that page
"Show logcat view if message priority is at least " select VERBOSE.
This happens when you don't close eclipse for a long duration, just close eclipse and reopen it, your problem should be solved.
Correct answer: it is/was a bug in Eclipse. All I did to trigger it was to rename one of the filter and pressing the Run button.
Restarting Eclipse fixes it.
In eclipse, go to: windows->preferences
Then go to Android->logcat and make sure you have the following setup:
1. double-click action: "go to problem (error line)
2. switch to: java
3. both checkboxes are checked
if your setup is fine, clean the project and restart eclipse
good luck!
Some times it does happen on a slower machine that eclipse waits for emulator HOME screen and after waiting too long it shows that the emulator is offline.
Secondly Make sure that you are looking in the correct filter or in all messages part.
Also you can do the following :
select the device and find your process (e.g. "com.android.myapp")
Look for its process id written to its left (eg. 17260)
Now go to logcat and add a new filter by witting a particular name and the specific Pid (say 17260)
Now select that filter and you'l be able to see your log messages
Good Luck!
I had the same issue, but gave up on eclipse logcat panel and switched to cygwin+adb:
make sure the app is running and launch cygwin
cd /cygdrive/c/android_sdk/sdk/platform-tools #go to where adb.exe is
[optional] ./adb logcat -c #clean the log, obviously don't do this if you want to see some old messages
./adb logcat #see all messages
or
./adb logcat | grep "whatever" #look only for whatever you want to look for
Go to Device from DDMS and open it.
Select your device from which device your application is running
Select your project which you run on this device
I had this issue for the last few days and tried everything above.
As it turned out, my problem was that all my log statements were in a class that was not being reached. I thought it had because of what was being displayed but that was not the case.
So in short, check with the following
Post log statements at the beginning of every method.
I too had the same problem , and I solved the issue by
-> restart the eclipse
-> go to ddms -> click on the emulator
I tried all the above solutions, but nothing did work. Then, I saw I had a button named "R", then something clicked in my mind, I renamed it to:
R1=(Button) findViewById(R.id.button1);
So maybe it was conflicting with R of Android and Java name of a button "R".
Hurray error got resolved.
Let us conclude with the following steps:
Check if u have any variable(button,textview) name which is “R”
Save your project, close Eclipse and then open it again.
Project --> clean
import android.R; remove this.
Correct answer: it is/was a bug in Eclipse. All I did to trigger it was to rename one of the filter and pressing the Run button. Restarting Eclipse fixes it.
You might have switched off LogCat by Mistake
Go to Preferences>Android
Click LogCat and make sure there is a check next to "Monitor logcat for messages from applications in workspace"
Then select the dropdown "Show logcat view if message priority is at least" and choose "VERBOSE" (or depending on how you tag your Logs, but VERBOSE will get all output)
Click "Apply" and you should start seeing your messages again
Make sure that you set
android:debuggable="true"
in your manifest file.
I was facing the same problem and the following steps resolved the issue:
Restart my Eclipse
Restart my Emulator
Select devices tab from DDMS perspective in Eclipse.
Check the device is not at fault. My device was set not to log, accidentally disabled it via boeffla kernel. After turning it back on logcat worked fine.
Go to windows->preference->android->logcat
select the option -
show logcat if message priority is atleat verbose.
It will show all the events of device and close all the perpestive and open logcat it will be working again.
On right top corner click on "Display Saved Filter View" or if "display saved filter view" is already open then just click on the red - icon to delete selected logcat filter.

How do I pause the command window when launching an app?

When I launch an Android app via Ctrl+F11 on Eclipse, there are two black command windows (DOS-like) that appear briefly with some important messages in them. Obviously, I can't read what's in them in that brief moment.
Is there a way to pause/freeze them?
Update: #Mayra's answers below provided great tips but they did not solve the problem of pausing/freezing these windows. I know for sure that they contain information not in the Console and not in the logcat. So the question remains.
I'm not sure what windows you are referring to, but you shouldn't have to do anything like that.
All relevant information is displayed in either the Console or logcat tabs. You can open either via window -> show view.
You can also access logcat by running adb logcat from the command line.
Unless an answer that describes step-by-step how to pause the command window when launching an android app from Eclipse (to the emulator) comes along, the accepted answer is: This cannot be done.

Android Emulator Debugging, Code will not Update

I'm having a troubling problem testing some code for and Android app. My app has two parts, and activity where the user changes some settings, and a broadcast receiver that responds to SMS messages, both in the same package.
Here's the problem, I first implemented some simple code to test out the broadcast receiver and the activity, and both worked fine. But then as I tried to refine the code, I noticed the emulator wasn't picking up any of my changes. Event went so far as to uninstall the app from the emulator and try again, no luck. Then I added some extra Toast popups to my receiver, nothing, still running the old code. I know its running the old code because its sending out an SMS using a string constant that is no longer in the current code, so it should be impossible that it respond with that value.
Here's the kicker that has me confused. For fun I made a change to my activity. Ran the project from Eclipse and that change showed up! Tried to test the receiver code again, runs the old code that doesn't even exist anymore!!
How in the world can half the package update, and the other half not?
Can anyone help me out 'cause I'm about ready to lose my mind.
I had a similar problem. Changes made to classes imported from another project didn't get picked up by eclipse, but those made to classes in the current android project were.
Making a change to the current android project (inserting a blank line and deleting it) seemed to make eclipse pick up all the changes made and upload the app to the emulator.
I had this problem too, Now I found a working solution. Just follow these steps:
Run your project normally.
When emulator started, run your project again (DO NOT close the first emulator)
Then the updated application will be uploaded into emulator
I can't really be sure what happened but creating an new emulator image appeared to solve the issue.
I don't know why it happens but it's a problem I have all the time.
What I typically do is
Close the emulator
Close Eclipse
Reopen Eclipse
Clean the projects (in Eclipse, select Project -> Clean... -> Clean all projects)
Rerun the emulator
Annoying as hell but seems to work for me.
I'm having this problem too. It mostly happens when errors are entered into the code. The strange thing is if I go back to the original code, Eclipse doesn't revert to the original code. One thing that seems to help is to temporary delete the contents of a file, save, and rebuild, and then enter the contents back into the file, save, and rebuild.
How is one supposed to debug in such an environment?

Categories

Resources