How to determine the source of a log in LogCat? - android

Is it possible to determine the location in code, where a particular message was written to LogCat?
I would like to have something like a stack trace for each log, since some logs are of unknown source.

Why don't you use Android Debug or simply try to show Log.v("Your messsage"+your response) where ever needed. So that you can get idea where your application reached at that particular time when that Log prints on your LogCat

Related

App crashes after trying to plot data from firebase using MpAndroid Chart [duplicate]

I am developing an application, and everytime I run it, I get the message:
Unfortunately, MyApp has stopped.
What can I do to solve this?
About this question - obviously inspired by What is a stack trace, and how can I use it to debug my application errors?, there are lots of questions stating that their application has crashed, without any further detail. This question aims to instruct novice Android programmers on how to try and fix their problems themselves, or ask the right questions.
This answer describes the process of retrieving the stack trace. Already have the stack trace? Read up on stack traces in "What is a stack trace, and how can I use it to debug my application errors?"
The Problem
Your application quit because an uncaught RuntimeException was thrown.
The most common of these is the NullPointerException.
How to solve it?
Every time an Android application crashes (or any Java application for that matter), a Stack trace is written to the console (in this case, logcat). This stack trace contains vital information for solving your problem.
Android Studio
In the bottom bar of the window, click on the Logcat button. Alternatively, you can press alt+6. Make sure your emulator or device is selected in the Devices panel. Next, try to find the stack trace, which is shown in red. There may be a lot of stuff logged into logcat, so you may need to scroll a bit. An easy way to find the stack trace is to clear the logcat (using the recycle bin on the right), and let the app crash again.
I have found the stack trace, now what?
Yay! You're halfway to solving your problem.
You only need to find out what exactly made your application crash, by analyzing the stack trace.
Read up on stack traces in "What is a stack trace, and how can I use it to debug my application errors?"
I still can't solve my problem!
If you've found your Exception and the line where it occurred, and still cannot figure out how to fix it, don't hesitate to ask a question on StackOverflow.
Try to be as concise as possible: post the stack trace, and the relevant code (e.g. a few lines up to the line which threw the Exception).
You can use Google's ADB tool to get Logcat file to analyze the issue.
adb logcat > logcat.txt
open logcat.txt file and search for your application name. There should be information on why it failed, the line number, Class name, etc.
First, you check which point your app has crashed (Unfortunately, MyApp has stopped.). For this, you can use Log.e("TAG", "Message");, using this line you can see your app log in logcat.
After that, you find which point your app has stopped it's very easy to solve at your side.
Just check the error in log cat.
You get the log cat option from in eclipse:
window->show view->others->Android->Logcat
Log cat contains error.
Other wise you can also check the error by executing an application in debug mode.
Firstly set breakpoint after that by doing:
right click on project->debug as->Android application
Note: This answer is using Android Studio 2.2.2
Note 2: I am considering that your device is successfully connected.
The first thing you do when your application crashes is looking into the LogCat, at the bottom of Android Studio there's a toolbar with a list of menus:
Click on the "Android Monitor" (The one I underlined in the image above. ^)
Now, you'll get something like this:
Change "Verbose" to "Error" Now it will only show you logged errors. Don't worry about all these errors (if you got them) now.
Ok. Now, do what you did to crash your app. After your app crashes, go to your logcat. You should find a new crash log that has a lot of at:x.x.x: and Caused by: TrumpIsPresidentException for example. Go to that Caused by: statement in your logcat.
Next to that Caused By:, there should be the Exception that happened. In my case, it's a RuntimeException and under it there should be a line that contains a blue link such as:
If that Caused by: DOESN'T have a line with a blue text somewhere under it, then look for another Caused by: that does.
Click on that blue link. It should take you to where the problem occurred. In my case, it was due to this line:
throw new RuntimeException();
So, now I know why it's crashing. It's because I'm throwing the exception myself. This was an obvious error.
However, let's say I got another error:
java.lang.NullPointerException
I checked my logcat, I clicked on the blue link it gave me, and it took me here:
mTextView.setText(myString);
So, now I want to debug. According to this StackOverflow question, a NullPointerException says that something is null.
So, let's find out what is null. There are two possibilities. Either mTextView is null, or myString is null. To find out, before the mTextView.setText(mString) line, I add these two lines:
Log.d("AppDebug","mTextView is null: " + String.valueOf(mTextView == null);
Log.d("AppDebug","myString is null: " + String.valueOf(myString== null);
Now, like we did previously (We changed Verose to Error), we want to change "Error" to "Debug". Since we're logging by debugging. Here are all the Log methods:
Log.
d means Debug
e means error
w means warning
v means verbose
i means information
wtf means "What a terrible failure". This is similar to Log.e
So, since we used Log.d, we're checking in Debug. That's why we changed it to debug.
Notice Log.d has a first parameter,in our case "AppDebug". Click on the "No Filters" drop down menu on the top-right of the logcat. Select "Edit Filter Configuration", give a name to your filter, and in "Log Tag" put "App Debug". Click "OK". Now, you should see two lines in the logcat:
yourPackageNameAndApp: mTextView is null: true
yourPackageNameAndApp: myString is null: false
So now we know that mTextView is null.
I observe my code, now I notice something.
I have private TextView mTextView declared at the top of my class. But, I'm not defining it.
Basically, I forgot to do this in my onCreate():
mTextView = (TextView) findViewById(R.id.textview_id_in_xml);
So THAT'S why mTextView is null, because I forgot to tell my app what it is. So I add that line, run my app, and now the app doesn't crash.
This popup shows only when you get a fatal exception in your code which stops the execution of the app. It could be any exception NullPointerException, OutOfMemoryException etc.
Best way to check is through Logcat if you are still developing the app in Android studio which is quick way to read stack trace and check the cause of the app.
If your app is already live, then you can not use logcat. So, for that you can implement Crashlytics to provide you bug reports of any exception that occurs.
Check your Logcat message and see your Manifest file. There should be something missing like defining the Activity,User permission`, etc.
You can use any of these tools:
adb logcat
adb logcat > logs.txt (you can use editors to open and search errors.)
eclipse logcat (If not visible in eclipse, Go to Windows->Show View->Others->Android->LogCat)
Android Debug Monitor or Android Device Monitor(type command monitor or open through UI)
Android Studio
I suggest to use Android Debug Monitor, it is good. Because eclipse hangs when too many logs are there, and through adb logcat filter and all difficult.
You have to check the Stack trace
How to do that?
on Your IDE Check the windows form LOGCAT
If you cant see the logcat windows go to this path and open it
window->show view->others->Android->Logcat
if you are using Google-Api go to this path
adb logcat > logcat.txt
In below showToast() method you have to pass another parameter for context or application context by doing so you can try it.
public void showToast(String error, Context applicationContext){
LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.custom_toast, (ViewGroup)
findViewById(R.id.toast_root));
TextView text = (TextView) findViewById(R.id.toast_error);
text.setText(error);
Toast toast = new Toast(applicationContext);
toast.setGravity(Gravity.TOP | Gravity.FILL_HORIZONTAL, 0, 0);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(view);
toast.show();
}
Let me share a basic Logcat analysis for when you meet a Force Close (when the app stops working).
DOCS
The basic tool from Android to collect/analyze logs is the logcat.
HERE is the Android's page about logcat
If you use android Studio, you can also check this LINK.
Capturing
Basically, you can MANUALLY capture logcat with the following command (or just check AndroidMonitor window in AndroidStudio):
adb logcat
There's a lot of parameters you can add to the command which helps you to filter and display the message that you want... This is personal... I always use the command below to get the message timestamp:
adb logcat -v time
You can redirect the output to a file and analyze it in a Text Editor.
Analyzing
If you app is Crashing, you'll get something like:
07-09 08:29:13.474 21144-21144/com.example.khan.abc D/AndroidRuntime: Shutting down VM
07-09 08:29:13.475 21144-21144/com.example.khan.abc E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.khan.abc, PID: 21144
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v4.app.FragmentActivity.onBackPressed()' on a null object reference
at com.example.khan.abc.AudioFragment$1.onClick(AudioFragment.java:125)
at android.view.View.performClick(View.java:4848)
at android.view.View$PerformClick.run(View.java:20262)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5631)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
07-09 08:29:15.195 21144-21144/com.example.khan.abc I/Process: Sending signal. PID: 21144 SIG: 9
This part of the log shows you a lot of information:
When the issue happened: 07-09 08:29:13.475
It is important to check when the issue happened... You may find several errors in a log... you must be sure that you are checking the proper messages :)
Which app crashed: com.example.khan.abc
This way, you know which app crashed (to be sure that you are checking the logs about your message)
Which ERROR: java.lang.NullPointerException
A NULL Pointer Exception error
Detailed info about the error: Attempt to invoke virtual method 'void android.support.v4.app.FragmentActivity.onBackPressed()' on a null object reference
You tried to call method onBackPressed() from a FragmentActivity object. However, that object was null when you did it.
Stack Trace: Stack Trace shows you the method invocation order... Sometimes, the error happens in the calling method (and not in the called method).
at com.example.khan.abc.AudioFragment$1.onClick(AudioFragment.java:125)
Error happened in file com.example.khan.abc.AudioFragment.java, inside onClick() method at line: 125 (stacktrace shows the line that error happened)
It was called by:
at android.view.View.performClick(View.java:4848)
Which was called by:
at android.view.View$PerformClick.run(View.java:20262)
which was called by:
at android.os.Handler.handleCallback(Handler.java:815)
etc....
Overview
This was just an overview... Not all logs are simple but the error gives specific problem and verbose shows up all problem ... It is just to share the idea and provide entry-level information to you...
I hope I could help you someway...
Regards
Use the LogCat and try to find what is causing the app to crash.
To see Logcat if you use Android Studio then Press ALT + 6
or
if you use Eclipse then
Window -> Open Perspective -> Other - LogCat
Go to the LogCat, from the drop down menu select error. This will contain all the required information to help you debug. If that doesn't help, post the LogCat as an edit to your question and somebody will help you out.
If your app for some reason crashes without good stacktrace. Try debug it from first line, and go line by line until crash. Then you will have answer, which line is causing you trouble. Proably you could then wrapp it into try catch block and print error output.
You can also get this error message on its own, without any stack trace or any further error message.
In this case you need to make sure your Android manifest is configured correctly (including any manifest merging happening from a library and any activity that would come from a library), and pay particular attention to the first activity displayed in your application in your manifest files.
People make mistakes, and so coding as well.
When ever any error happened, always check with the logcat with the text in red color however u can find out the real problem in blue color text with underline in those red color text.
Make sure if u create a new activity, always declare the activity in the AndroidManifest file.
If adding Permission, declare it in the AndroidMainifest file as well.
Logcat - To check the logs in the development phase of Android Studio
Initially clear the Logcat and let the app crash again so you can get only crashed log detail. You have to check the Stack trace
While, Unfortunately, MyApp has stopped. There are many reasons for it. You can check same in logs. For this, you can use the Log.e("TAG","Message");
Common error during app crash like:
Coding mistake(Wrong use of keywords).
Mismatch property name.
Unsupported plugin(maybe).
Mismatch version(maybe).
Activity missing in AndroidManifest file.
Permission missing in AndroidManifest file.
Most common NullPointerException.
Declared but not defined.
To resolve app crash error:
Keep in mind above points and go through it.
With the error, you will get the file name also in blue colour (click on them and jump to code from error is occurring).
Crash during development
Try my favourite tool logview to get the logs and analyze them during development.
Make sure to mark ./logview and ./lib/logview.jar as executable when running in Linux.
If you don't like it, there're a lot of alternative desktop log viewers for Android.
Crash in the wild
Integrate a real-time crash reporting tool such as Firebase Crashlytics in order to get stacktraces of unhandled exceptions which occurred on users' devices.
Read How to Release a Buggy App (And Live to Tell the Tale) to know more about handling bugs in the field.
If you don't have any kind of interesting log in your terminal (or they are not directly related to your app), maybe your problem is due to a native library. In that case, you should check for the "tombstone" files within your terminal.
The default location for the tombstone files depends on every device, but if that's the case, you will have a log telling: Tombstone written to: /data/tombstones/tombstone_06
For more information, check on https://source.android.com/devices/tech/debug.
First, you need to check where and why your app has been crashed (Unfortunately, MyApp has stopped.). With the help of LOG, you can figure it out what went wrong.
After that, you find which point your app has stopped fix that from your point.
Also running this command in terminal can help find the problem:
gradlew build > log.txt 2>details.txt
then you should go to gradlew file location in read two above log files.
I'll Suggest something like this.
Check if your phone has good enough space that the app can run----prior/
Check the logcat when the app crashes. It will show the exact line where the app crashed.
Check if you are using something on the main thread that uses a lot of memory due to ANR.
Check your Logcat message. Also, see your Manifest file for missing elements like defining the Activity, User permission, etc.
To see Logcat if you use Android Studio then Press alt+6
or
if you use Eclipse then
Window -> Open Perspective -> Other - LogCat
Now, from the drop-down menu select error.
Alternatively, you can use ADB tool to get the Logcat file to analyze the issue.
adb logcat > logcat.txt
Now open the logcat.txt file and search for your application name. There should be information on why it failed, the line number, Class name, etc.
If your app crashed without any errors, and you didn't use an asset manager but loaded the textures like:
Texture texture = new Texture("myImage.png"); //dont to this all the time
then that's the problem. I had that happen to me. You should always use an asset manager to avoid a memory overload.

Android Studio: Logcat vs Run

What's the difference between Logcat and Run in Android-Studio?
Logcat has filter-options. Beside that I don't get which specific purpose each serve.
In how far do the messages differ, which become printed to each console?
When do I use which console?
Personally,Logcat is more useful for debugging and being aware of what is going on while the app is running. You set the type of the log and set tags to them, by this way you can easily filter logs. This gives you much more clear picture in terms of logging.it stated in this article
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.
Also, it is stated that (in the same article)
The priority is one of the following character values, ordered from lowest to highest priority:
V: Verbose (lowest priority)
D: Debug
I: Info
W: Warning
E: Error
F: Fatal
S: Silent (highest priority, on which nothing is ever printed)
each one of these shows the logs from their priority to highest one . Verbose, for instance, will print all the logs but if you switch to error , logcat only shows error and fatal logs.
Additionally, if you set a tag filter it will only shows the logs that is tagged with that "tag", of course while keeping the priority filter. For instance
Log.e("tag1","message_1");
Log.e("tag2","message_2");
Assume you have filter the tags with "tag1". The logcat will print "message_1".
Similarly
Log.e("tag1","message_1");
Log.i("tag1","message_2");
Again, assume that you have filter tags by "tag1" and priorities with Error.Then, the logcat will show only "message_1".
For the run tool also shows logs , prints (println etc.) but in comparison with the logcat it will show a lot more stuff (logs, prints (println etc. and phone related informations).
apart from your logs other logs that comes from libraries and phone itself also are shown in the run tool. So it hard to find your own logs.
Run will be useful when the phone and library related information logs needed.(for instance when the phone misses/drop frames it will be printed in run)
Logcat will be useful for your own logs.When you are trying to understand what is going on while the app runs etc..
I have noticed a big difference between the run and the logcat while using avd emulators. I had a deceiving crash on my app, only while I was using the emulators .
every time there was a crash , the logs before the crash were disappearing from the logcat , and I couldn't understand if I see the logs related to the crash. after a week of trying to find a library that prints the logs to a file I found out that everything is printed in the run tab, so I don't need that.

Not getting Android logging in adb?

I'm running a Unity3D app and have put some prints (Debug.Log and print) around the code which should be getting hit. I've confirmed that they are and have made sure all logging in build settings are set to 'Full'.
Not sure why the output isn't coming through in adb logcat. However interestingly null reference exceptions are being printed so there must be something going on there..
For example I have the following code in ana update function in a scene (and nothing else):
void Update(){
print("WILL THIS WORK?");
Debug.Log("####################### I AM HERE");
object o = null;
print(o.GetType());
}
adb logcat shows the following output:
I just found the only type of logging which works is Debug.Error, so this might have to do with some level of error logging but not sure what it could be, in my inspector I have the following set:
So it should log everything..
Pay attention to your screenshot. You cannot see your own log because Unity is showing its own error. Usually, when you get an error the rest of the code in that frame is abandoned until the next frame. This used to be the behavior of Unity and I think it's still the behavior and your current issue. That error in your Update function in the Platform.TestAuth script.
Fix the NullReferenceException you are getting and then you should be able to see your log appear.

How to perform a Sqlite query in android by using a search value in Android? [duplicate]

I am developing an application, and everytime I run it, I get the message:
Unfortunately, MyApp has stopped.
What can I do to solve this?
About this question - obviously inspired by What is a stack trace, and how can I use it to debug my application errors?, there are lots of questions stating that their application has crashed, without any further detail. This question aims to instruct novice Android programmers on how to try and fix their problems themselves, or ask the right questions.
This answer describes the process of retrieving the stack trace. Already have the stack trace? Read up on stack traces in "What is a stack trace, and how can I use it to debug my application errors?"
The Problem
Your application quit because an uncaught RuntimeException was thrown.
The most common of these is the NullPointerException.
How to solve it?
Every time an Android application crashes (or any Java application for that matter), a Stack trace is written to the console (in this case, logcat). This stack trace contains vital information for solving your problem.
Android Studio
In the bottom bar of the window, click on the Logcat button. Alternatively, you can press alt+6. Make sure your emulator or device is selected in the Devices panel. Next, try to find the stack trace, which is shown in red. There may be a lot of stuff logged into logcat, so you may need to scroll a bit. An easy way to find the stack trace is to clear the logcat (using the recycle bin on the right), and let the app crash again.
I have found the stack trace, now what?
Yay! You're halfway to solving your problem.
You only need to find out what exactly made your application crash, by analyzing the stack trace.
Read up on stack traces in "What is a stack trace, and how can I use it to debug my application errors?"
I still can't solve my problem!
If you've found your Exception and the line where it occurred, and still cannot figure out how to fix it, don't hesitate to ask a question on StackOverflow.
Try to be as concise as possible: post the stack trace, and the relevant code (e.g. a few lines up to the line which threw the Exception).
You can use Google's ADB tool to get Logcat file to analyze the issue.
adb logcat > logcat.txt
open logcat.txt file and search for your application name. There should be information on why it failed, the line number, Class name, etc.
First, you check which point your app has crashed (Unfortunately, MyApp has stopped.). For this, you can use Log.e("TAG", "Message");, using this line you can see your app log in logcat.
After that, you find which point your app has stopped it's very easy to solve at your side.
Just check the error in log cat.
You get the log cat option from in eclipse:
window->show view->others->Android->Logcat
Log cat contains error.
Other wise you can also check the error by executing an application in debug mode.
Firstly set breakpoint after that by doing:
right click on project->debug as->Android application
Note: This answer is using Android Studio 2.2.2
Note 2: I am considering that your device is successfully connected.
The first thing you do when your application crashes is looking into the LogCat, at the bottom of Android Studio there's a toolbar with a list of menus:
Click on the "Android Monitor" (The one I underlined in the image above. ^)
Now, you'll get something like this:
Change "Verbose" to "Error" Now it will only show you logged errors. Don't worry about all these errors (if you got them) now.
Ok. Now, do what you did to crash your app. After your app crashes, go to your logcat. You should find a new crash log that has a lot of at:x.x.x: and Caused by: TrumpIsPresidentException for example. Go to that Caused by: statement in your logcat.
Next to that Caused By:, there should be the Exception that happened. In my case, it's a RuntimeException and under it there should be a line that contains a blue link such as:
If that Caused by: DOESN'T have a line with a blue text somewhere under it, then look for another Caused by: that does.
Click on that blue link. It should take you to where the problem occurred. In my case, it was due to this line:
throw new RuntimeException();
So, now I know why it's crashing. It's because I'm throwing the exception myself. This was an obvious error.
However, let's say I got another error:
java.lang.NullPointerException
I checked my logcat, I clicked on the blue link it gave me, and it took me here:
mTextView.setText(myString);
So, now I want to debug. According to this StackOverflow question, a NullPointerException says that something is null.
So, let's find out what is null. There are two possibilities. Either mTextView is null, or myString is null. To find out, before the mTextView.setText(mString) line, I add these two lines:
Log.d("AppDebug","mTextView is null: " + String.valueOf(mTextView == null);
Log.d("AppDebug","myString is null: " + String.valueOf(myString== null);
Now, like we did previously (We changed Verose to Error), we want to change "Error" to "Debug". Since we're logging by debugging. Here are all the Log methods:
Log.
d means Debug
e means error
w means warning
v means verbose
i means information
wtf means "What a terrible failure". This is similar to Log.e
So, since we used Log.d, we're checking in Debug. That's why we changed it to debug.
Notice Log.d has a first parameter,in our case "AppDebug". Click on the "No Filters" drop down menu on the top-right of the logcat. Select "Edit Filter Configuration", give a name to your filter, and in "Log Tag" put "App Debug". Click "OK". Now, you should see two lines in the logcat:
yourPackageNameAndApp: mTextView is null: true
yourPackageNameAndApp: myString is null: false
So now we know that mTextView is null.
I observe my code, now I notice something.
I have private TextView mTextView declared at the top of my class. But, I'm not defining it.
Basically, I forgot to do this in my onCreate():
mTextView = (TextView) findViewById(R.id.textview_id_in_xml);
So THAT'S why mTextView is null, because I forgot to tell my app what it is. So I add that line, run my app, and now the app doesn't crash.
This popup shows only when you get a fatal exception in your code which stops the execution of the app. It could be any exception NullPointerException, OutOfMemoryException etc.
Best way to check is through Logcat if you are still developing the app in Android studio which is quick way to read stack trace and check the cause of the app.
If your app is already live, then you can not use logcat. So, for that you can implement Crashlytics to provide you bug reports of any exception that occurs.
Check your Logcat message and see your Manifest file. There should be something missing like defining the Activity,User permission`, etc.
You can use any of these tools:
adb logcat
adb logcat > logs.txt (you can use editors to open and search errors.)
eclipse logcat (If not visible in eclipse, Go to Windows->Show View->Others->Android->LogCat)
Android Debug Monitor or Android Device Monitor(type command monitor or open through UI)
Android Studio
I suggest to use Android Debug Monitor, it is good. Because eclipse hangs when too many logs are there, and through adb logcat filter and all difficult.
You have to check the Stack trace
How to do that?
on Your IDE Check the windows form LOGCAT
If you cant see the logcat windows go to this path and open it
window->show view->others->Android->Logcat
if you are using Google-Api go to this path
adb logcat > logcat.txt
In below showToast() method you have to pass another parameter for context or application context by doing so you can try it.
public void showToast(String error, Context applicationContext){
LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.custom_toast, (ViewGroup)
findViewById(R.id.toast_root));
TextView text = (TextView) findViewById(R.id.toast_error);
text.setText(error);
Toast toast = new Toast(applicationContext);
toast.setGravity(Gravity.TOP | Gravity.FILL_HORIZONTAL, 0, 0);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(view);
toast.show();
}
Let me share a basic Logcat analysis for when you meet a Force Close (when the app stops working).
DOCS
The basic tool from Android to collect/analyze logs is the logcat.
HERE is the Android's page about logcat
If you use android Studio, you can also check this LINK.
Capturing
Basically, you can MANUALLY capture logcat with the following command (or just check AndroidMonitor window in AndroidStudio):
adb logcat
There's a lot of parameters you can add to the command which helps you to filter and display the message that you want... This is personal... I always use the command below to get the message timestamp:
adb logcat -v time
You can redirect the output to a file and analyze it in a Text Editor.
Analyzing
If you app is Crashing, you'll get something like:
07-09 08:29:13.474 21144-21144/com.example.khan.abc D/AndroidRuntime: Shutting down VM
07-09 08:29:13.475 21144-21144/com.example.khan.abc E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.khan.abc, PID: 21144
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v4.app.FragmentActivity.onBackPressed()' on a null object reference
at com.example.khan.abc.AudioFragment$1.onClick(AudioFragment.java:125)
at android.view.View.performClick(View.java:4848)
at android.view.View$PerformClick.run(View.java:20262)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5631)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
07-09 08:29:15.195 21144-21144/com.example.khan.abc I/Process: Sending signal. PID: 21144 SIG: 9
This part of the log shows you a lot of information:
When the issue happened: 07-09 08:29:13.475
It is important to check when the issue happened... You may find several errors in a log... you must be sure that you are checking the proper messages :)
Which app crashed: com.example.khan.abc
This way, you know which app crashed (to be sure that you are checking the logs about your message)
Which ERROR: java.lang.NullPointerException
A NULL Pointer Exception error
Detailed info about the error: Attempt to invoke virtual method 'void android.support.v4.app.FragmentActivity.onBackPressed()' on a null object reference
You tried to call method onBackPressed() from a FragmentActivity object. However, that object was null when you did it.
Stack Trace: Stack Trace shows you the method invocation order... Sometimes, the error happens in the calling method (and not in the called method).
at com.example.khan.abc.AudioFragment$1.onClick(AudioFragment.java:125)
Error happened in file com.example.khan.abc.AudioFragment.java, inside onClick() method at line: 125 (stacktrace shows the line that error happened)
It was called by:
at android.view.View.performClick(View.java:4848)
Which was called by:
at android.view.View$PerformClick.run(View.java:20262)
which was called by:
at android.os.Handler.handleCallback(Handler.java:815)
etc....
Overview
This was just an overview... Not all logs are simple but the error gives specific problem and verbose shows up all problem ... It is just to share the idea and provide entry-level information to you...
I hope I could help you someway...
Regards
Use the LogCat and try to find what is causing the app to crash.
To see Logcat if you use Android Studio then Press ALT + 6
or
if you use Eclipse then
Window -> Open Perspective -> Other - LogCat
Go to the LogCat, from the drop down menu select error. This will contain all the required information to help you debug. If that doesn't help, post the LogCat as an edit to your question and somebody will help you out.
If your app for some reason crashes without good stacktrace. Try debug it from first line, and go line by line until crash. Then you will have answer, which line is causing you trouble. Proably you could then wrapp it into try catch block and print error output.
You can also get this error message on its own, without any stack trace or any further error message.
In this case you need to make sure your Android manifest is configured correctly (including any manifest merging happening from a library and any activity that would come from a library), and pay particular attention to the first activity displayed in your application in your manifest files.
People make mistakes, and so coding as well.
When ever any error happened, always check with the logcat with the text in red color however u can find out the real problem in blue color text with underline in those red color text.
Make sure if u create a new activity, always declare the activity in the AndroidManifest file.
If adding Permission, declare it in the AndroidMainifest file as well.
Logcat - To check the logs in the development phase of Android Studio
Initially clear the Logcat and let the app crash again so you can get only crashed log detail. You have to check the Stack trace
While, Unfortunately, MyApp has stopped. There are many reasons for it. You can check same in logs. For this, you can use the Log.e("TAG","Message");
Common error during app crash like:
Coding mistake(Wrong use of keywords).
Mismatch property name.
Unsupported plugin(maybe).
Mismatch version(maybe).
Activity missing in AndroidManifest file.
Permission missing in AndroidManifest file.
Most common NullPointerException.
Declared but not defined.
To resolve app crash error:
Keep in mind above points and go through it.
With the error, you will get the file name also in blue colour (click on them and jump to code from error is occurring).
Crash during development
Try my favourite tool logview to get the logs and analyze them during development.
Make sure to mark ./logview and ./lib/logview.jar as executable when running in Linux.
If you don't like it, there're a lot of alternative desktop log viewers for Android.
Crash in the wild
Integrate a real-time crash reporting tool such as Firebase Crashlytics in order to get stacktraces of unhandled exceptions which occurred on users' devices.
Read How to Release a Buggy App (And Live to Tell the Tale) to know more about handling bugs in the field.
If you don't have any kind of interesting log in your terminal (or they are not directly related to your app), maybe your problem is due to a native library. In that case, you should check for the "tombstone" files within your terminal.
The default location for the tombstone files depends on every device, but if that's the case, you will have a log telling: Tombstone written to: /data/tombstones/tombstone_06
For more information, check on https://source.android.com/devices/tech/debug.
First, you need to check where and why your app has been crashed (Unfortunately, MyApp has stopped.). With the help of LOG, you can figure it out what went wrong.
After that, you find which point your app has stopped fix that from your point.
Also running this command in terminal can help find the problem:
gradlew build > log.txt 2>details.txt
then you should go to gradlew file location in read two above log files.
I'll Suggest something like this.
Check if your phone has good enough space that the app can run----prior/
Check the logcat when the app crashes. It will show the exact line where the app crashed.
Check if you are using something on the main thread that uses a lot of memory due to ANR.
Check your Logcat message. Also, see your Manifest file for missing elements like defining the Activity, User permission, etc.
To see Logcat if you use Android Studio then Press alt+6
or
if you use Eclipse then
Window -> Open Perspective -> Other - LogCat
Now, from the drop-down menu select error.
Alternatively, you can use ADB tool to get the Logcat file to analyze the issue.
adb logcat > logcat.txt
Now open the logcat.txt file and search for your application name. There should be information on why it failed, the line number, Class name, etc.
If your app crashed without any errors, and you didn't use an asset manager but loaded the textures like:
Texture texture = new Texture("myImage.png"); //dont to this all the time
then that's the problem. I had that happen to me. You should always use an asset manager to avoid a memory overload.

How to output messages to the Eclipse console when developing for Android

How can I print messages (like a flag) to the Eclipse console (or log) when developing and debugging an Android app
Rather than trying to output to the console, Log will output to LogCat which you can find in Eclipse by going to: Window->Show View->Other…->Android->LogCat
Have a look at the reference for Log.
The benefits of using LogCat are that you can print different colours depending on your log type, e.g.: Log.d prints blue, Log.e prints orange. Also you can filter by log tag, log message, process id and/or by application name. This is really useful when you just want to see your app's logs and keep the other system stuff separate.
Log.v("blah", "blah blah");
You need to add the android Log view in eclipse to see them. There are also other methods depending on the severity of the message (error, verbose, warning, etc..).
System.out.println() also outputs to LogCat. The benefit of using good old System.out.println() is that you can print an object like System.out.println(object) to the console if you need to check if a variable is initialized or not.
Log.d, Log.v, Log.w etc methods only allow you to print strings to the console and not objects. To circumvent this (if you desire), you must use String.format.
I use Log.d method also please import import android.util.Log;
Log.d("TAG", "Message");
But please keep in mind that, when you want to see the debug messages then don't use Run As
rather use "Debug As" then select Android Application. Otherwise you'll not see the debug messages.
i use below log format for print my content in logCat
Log.e("Msg","What you have to print");

Categories

Resources