Code Monkey home page Code Monkey logo

how-to-see-logcat's Introduction

How-to-see-logcat

How about finding your error by yourself ?

Solution:-

The best way to learn is to solve problem by yourself. Here I'll tell you how to proceed when your app crashes suddenly and you have no idea.

If your application crashes then we'll be looking for " logcat ".

What is logcat ?

Logcat is a command-line tool that dumps a log of system messages, including stack traces when the device throws an error and messages that you have written from your app with the Log class.

For more https://developer.android.com/studio/command-line/logcat.html

a) You will find logcat at the bottom of your Android Studio Screen.

logcat

b) Click "logcat" and there you will see lot of messages(logs).

logcat2

c) Next step is to filter our logcat to error mode so that we can see only those message which are related to error. Change your logcat from verbose to error mode and here is your logcat for error.

errormode

Great!! now you know how to open logcat. Now let's learn how to use it.

Let's take an example and with the same concept you can solve any problem. The Below program converts two string numbers into integers, calculates the sum and prints the result in TextView as you can see the layout.xml below.. but to learn how to use logcat I have made mistake in this code..Let's resolve the error by seeing the logcat.

MainActivity.java

example

activity_main.xml

resultlayout

But when we run the program, our program will crash so we'll open the logcat as we're told above.[Note : If you're using external device to run the app then it must remain conntectd to your android studio].The logcat for above example looks like :-

ssdfg

We will look only for the highlighted lines in logcat...we can see that logcat specifies error like "NumbeFormatException"...and also we see ' Invalid int: "abc" ' ,with a error of "NumbeFormatException" and ' Invalid int: "abc" ' we can guess that error is related to NumberConversion and also there is something wrong with int ...and you can see that these error occur in the Mainactivity.java by looking the path in the first line. So, we'll move back to MainActivity.java

Mainactivity.java

dfs

Now, we'll look our Mainactivity.java. Here you see that, we're not taking integers string for s1 so while parsing that string into integers, it creates error.

Tip :- Sometimes your logcat might not be easy to understand, or can more complex as compared to this example and you might not have any idea about the error, so in that case just copy the highlighted lines of your logcat and paste on google and in many cases you will get your solution on stack-overflow

Special thanks to :-

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.