简体   繁体   中英

Why can't I see my print statements in Logcat?

I trying to debug code on my first Android program. I started using the regular println and it worked in the earlier main(onCreate) method, showing the results in LogCat. However, it doesn't seem to work below, so then I started trying to work out Log.i/Log.d to no sucess. I'm basically trying to see if the program actually runs the below method - although no print statements are produced in the LogCat, I think the code is actually running as when I hit the "new" or "exit"button on my app, it seems to fo to the correct place in the case statement and runs finish();

Any help with would be really appreciated in getting something printed to LogCat, so I can see what's going on.

Thank you

Ed Ryan



 public void onClick(final View v) {

        System.out.println("Here in  - onClick");
        switch (v.getId()) {
        case R.id.about_button:
           System.out.println("Here in  - onClick1");
           Intent i = new Intent(this, About.class);
           startActivity(i);
           break;
        case R.id.new_button:
            System.out.println("Here in  - onClick2");
            finish();
           //openNewGameDialog();
           break;
        case R.id.exit_button:
            Log.i("onDisabled","info");
            Log.d(TAG, "onDisabled");
            System.out.println("Here in  - onClick3");
           finish();
           break;
        }
     }


}//end class


I've experienced this while using LogCat within Eclipse. This happens when the device drops off or loses focus or when you're debugging using 2 or more different devices/emulators.

Try the following:

  1. Go to the DDMS perspective and double-click the application that you're debugging or at least the device. You should see the LogCat tab flood with the new messages.
  2. Remove all devices except the one you're working with at the moment.
  3. Try just using the Log.* functions again.
  4. Set the LogCat filter to Debug or Verbose.

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.

One clarification on Jeremy's answer. On the tip where he said...

"Remove all devices except the one you're working with at the moment."

It didn't work for me right away but after I did that and went into:

Run > Debug Configurations > target (tab on the right)

and clicked the box next to the device it worked fine. I am not sure if both the deleting of devices and checking the box were required, or if just checking the box would have been enough but I guess as long as it works its all good.

Jeremy Edwards is on the right track. You need to open the DDMS perspective and click your device's name. Then go back to your main perspective. Sometimes the log is still not showing what you want to see, so select the circled "V" above the logcat. This will display the logcat's verbose mode. Otherwise, you can filter it using i or d, which associate with Log.i or Log.d, respectively. Next, scroll to the bottom of the logcat to see the most recent messages from the device.

If you're trying to see the output of an AVD in Eclipse, sometimes Eclipse and the emulator get disconnected. Usually if you issue these commands, things will clear up:

adb kill-server
adb start-server

Open up the Devices view and be sure that you see your device/AVD.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM