How can I diagnose a problem with Android? - java

Error I am getting:
Sorry!
The application {name} (process {package}) has stopped unexpectedly. Please try again.
The application fetches some data from the internet (my server) and then parse's it to take the data out of the XML. The program does not crash if the data is the same every time (empty every fetch or populated). But it seems to crash when the data changes even though the variables are not set as final and specify "new" on each instance.
The question: is it possible to diagnose the problem more fully from Android? I am not getting any messages in the console (developing live on the phone linked to eclipse).
Thanks for your help!

To diagnose problems in Android it is important to look at the Logcat output. This is the standard output for all Android applications. If this is not helping you could think about using try/catch blocks around the problematic code part or I also would recommend to register a global UncaughtExceptionHandler that catches all exceptions that are nowhere else catched.

You could add a try/catch clause perhaps or typical Log.e messages wherever you feel it's crashing and print the stackTrace.
If it's linked to Eclipse, then the debugging messages should appear (unless you set your manifest feature to be non-debuggeable).

One thing to try is to look at the data that works and the one that doesnt, and note the differences. Then, in the xml that works, add a line of the xml that doesnt work. Do this line by line to determine what part (if at all it does) causes the error. This is assuming your code is okay but the data being sent is wrong.
Hm, before doing this make sure it is a data issue and not code.

Related

Google foobar responds with Error(400)

I'm trying to solve Google's foobar challenges. I'm not going to spoil the actual question for anyone else, but the title is "Save Beta Rabbit". My solution is coded in Java, and every time I try to verify it I get an Error(400): Bad request. This appears to be an error on their part. I've tested the code locally on my machine and it works fine. Also, if it was a problem with runtime or memory, foobar explicitly tells you that. It also explicitly tells you when you have complier errors. Anybody know anything about this? Challenge is on a timer here.
UPDATE: I've traced down where the bug is. When you recursively call the same static method twice, the bug occurs. Unless anyone else has seen this before, I'm going to report it to Google through the feedback mechanism and close this question.
I got the same error in a Java solution. Without getting into implementation details, it turns out it was a performance problem. After I fixed it the verifier worked.

How to specify a custom action on Java exception in Eclipse IDE?

I'm working in Java with Eclipse (Luna) and I would like to specify what action happens whenever my project throws an exception. In other words, anytime an error happens and Eclipse prints a stack trace to the console, I would like to run my own code to print the stack trace in my own debug window or save to a text file, for example.
I'm not sure if this is a problem for my java project (maybe by overriding printStackTrace()?) or for the IDE itself (through some setting, etc.) Either way it doesn't really matter since its just a debug feature and would be removed before I export anything public.
Thanks for your help
EDIT: To clarify, I'm not talking about exceptions only from a specific line/class. I'm familiar with try-catch blocks. What I want is to preform an action any time any exception or error happens anywhere in my code, even if there is a typo and my project wont compile.
NOTE: You cannot have your own debug window in IDE
If you want to log some of your exceptions to some file wherein latter on you can see, so its time you use log4j.
Start with this simple example.
You will find ample on google :)

Tracking a java program

I've currently got a snippet of java code running in eclipse, which has a bug somewhere. In fixing the bug, I'd like to see what the program's actually doing. I know Java traces where the program goes when it displays an error message; can I access that data to find out where I'm going wrong?
Thanks!
If you are not familiar with breakpoints and debugging process this tutorial from Vogella will help you. Breakpoints will help you to understand the flow of program and can see where it starts and stops.In debugging mode when you hover over variable you can actually see what's happening there and values as well. This way you will know where this error is coming from and what could be the solution.

How to properly debug Java (Android) using Eclipse?

I am having problems with debugging my code. One of my AsyncTasks throws a RuntimeException, but I don't know which line in my code is responsible for this. Since I am new to Eclipse and Java in general, all of this is rather confusing to me.
Eclipse's debugging window shows me that my AsyncTask has been suspended because of a RuntimeException. Below that, there are three lines which point out certain lines of code. However, those lines do not exist in my code which is why I do not know what causes my application to crash. Am I missing something essential about debugging in Java / Android?
These are the three lines which I am given, by the way:
ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker) line: 1086
ThreadPoolExecutor$Worker.run() line: 561
Thread.run() line: 1096
How am I supposed to work with that? Help would be greatly appreciated.
in the ddms you can get the message related to the error, warning or other type of messages into the logcat window if you can't able to find the logcat in the ddms then go to the menu Window->Show View->logcat click on that and you'll be able to see the message now in the same ddms you also get the device window from that select the device for you can able to debug or get the message from that device into the logcat.
now check this way you can find your error detail into this logcat details
You're best using the logcat - this will show the stacktrace and the error raised. I've never had great success stepping through the code in DDMS but with the errrors shown in the logcat it's normally pretty easy to work out why the error was raised.
See Pratik's answer for opening the logcat if it isn't visible within Eclipse.
Rajeev got it right - when you set a breakpoint on an exception, the debugger will break on the line that throws it, not the line that catches it. In this way, you can see what is causing the exception.

is it possible to replace the default "Force Close" dialog in Android?

I would like the users of my android app to have the option to email me the stacktrace of any uncaught exception that crashes my app. Originally I thought I would just wrap every entry point to my app in a try/catch block, but there are far too many of these even in my tiny app for this to be reasonable.
So what I am really looking for is a way to specify some method to be the default handler for any uncaught exceptions. Any suggestions?
You cannot do what the subject line states from an SDK application.
However:
So what I am really looking for is a
way to specify some method to be the
default handler for any uncaught
exceptions. Any suggestions?
Use Thread.setDefaultUncaughtExceptionHandler().
Also, consider using Flurry or DroidDrop or something for the actual delivery of your exception data.
You could also use Bugsense.com to get your exception data (it's free).
PS: I am the founder :)

Categories

Resources