11

Android (4.2.2) application developed in Java on Eclipse, I'm getting a crash but I can't figure out what in my code is causing it . . .

The stack trace doesn't reference any of my own source code . . .

Thread [<1> main] (Suspended (exception RuntimeException))
ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2255
ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2309 ActivityThread.access$700(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 157
ActivityThread$H.handleMessage(Message) line: 1289
ActivityThread$H(Handler).dispatchMessage(Message) line: 99 Looper.loop() line: 176 ActivityThread.main(String[]) line: 5317
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] Method.invoke(Object, Object...) line: 511 ZygoteInit$MethodAndArgsCaller.run() line: 1102 ZygoteInit.main(String[]) line: 869 NativeStart.main(String[]) line: not available [native method]

... I launch several activities in my app and all of them are wrapped in a try/catch but if I set breakpoints in the catch blocks they aren't being hit, and if I step over the code that launches the Activities nothing seems amiss. Nor is the system writing anything to Logcat indicating any exceptions (no filters on Logcat, full Verbose output).

Clicking on the above lines just gives me "source not found". Is there a way to see what Activity it's trying to start or what the nature of the exception is?

Amit K. Saha
  • 5,871
  • 2
  • 27
  • 35
user316117
  • 7,971
  • 20
  • 83
  • 158
  • this is not the whole stacktrace – Marcin Orlowski Jul 31 '15 at 21:41
  • 2
    try `adb logcat` in a command line to see the whole log from your device. sometimes IDE doesn't show all logs for some reason.. that might help to identify the problem – Gennadii Saprykin Jul 31 '15 at 22:17
  • @Marcin Orlowski What makes you think it's not the whole stacktrace? The only other content in the stack trace is several other threads that are all shown as still running. – user316117 Aug 03 '15 at 14:15
  • This looks like a debugger stopped at a breakpoint, not an exception stacktrace in logcat. – laalto Aug 03 '15 at 17:33

7 Answers7

10

After researching this I saw the answer to this question here:

How do I prevent exception catching in Android?

Which suggest to keep executing the code until you get info in your logcat that pertains to your code.

Just a note on using verbose, etc.
Also, I personally just focus on errors when I begin debugging. I find it's easier to read. I remove all the errors from the logcat before I start looking at warnings. Also with verbose, if the program is really not running well, the logcat can have trouble keeping up.

This is my own personal style of debugging, it's by no means law.

Good luck with this.

Community
  • 1
  • 1
6

First of all - try/catch is not the best way to get bullet proof application - usually big number of such blocks means that author is cloaking errors.

What's you probably did is passing some wrong arguments to some system method or simply you've got some platform specific error. I can't say what is that method basing only on your logcat.

How to find the bug? Probably most effective way is just set some log messages / breakpoints and debugging it line by line as long as you'll get this error once again. Then return here with more details if necessary.

piotrpo
  • 12,398
  • 7
  • 42
  • 58
  • That answer is too vague. I have plenty of breakpoints and log messages but they show nothing amiss. It doesn't happen while I'm doing step-into/step-overs (F5/F6 in Eclipse) in my own code; only when I "run" because it's happening in some other thread. From the stack trace it seems to be related to launching an activity so how do I get it to tell me what activity? – user316117 Aug 03 '15 at 17:22
  • I guess it is pretty clear which activity from ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2255 Clearly it is the ActivityClientRecord. Don't you have such activity? – Amit K. Saha Aug 03 '15 at 17:30
1

Try running in the IDE's debugger in debug mode. It will usually catch your exception. You may have to click on the different threads to see what is happening with each.

likejudo
  • 3,396
  • 6
  • 52
  • 107
1

Are you sure version 4.2.2 is correct? The AOSP code for ActivityThread.java does not show anything but comments on line 2255 for all the 4.2.2 tags. Without anything else to go on, if I were in this situation, I'd dive into the AOSP code to see if it provides any clue as to where things are going wrong.

Trebor Rude
  • 1,904
  • 1
  • 21
  • 31
1

What are the code block of onCreate() of ActivityClientRecord ?

  1. You should set several breakpoints. First at the place of invoking startActivity() then on the target activity's onCreate()'s first statement. Then you should go statement by statement to find out the exact cause.

If you still can not find out the problematic point, then catch Error not the Exception wrapping the startActivity(), then let us know if you can see anything useful information.

Amit K. Saha
  • 5,871
  • 2
  • 27
  • 35
  • @user316117 , I had such experience of not being able to catch the exception. Later catching the Error object helped me out to find the cause. Definitely worth of a shot. – Amit K. Saha Aug 03 '15 at 17:34
1

Try to add in your Application class following code:

public class App extends Application {

@Override
public void onCreate() {
    super.onCreate();
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(Thread thread, Throwable ex) {
            ex.printStackTrace();
        }
    });
}

}

jakubbialkowski
  • 1,546
  • 16
  • 24
1

In my experience, I have faced similar problems in finding the code that's causing a crash. Here's generally what I do in such cases:

  1. Increase the Log Buffer size - Sometimes, too many things happen in the Logcat and the stacktrace you're looking for has already been cleared. (For Android Studio, it's a little different)
  2. Apply a filter using your app name - This removes all the clutter of logs from other apps. If still no luck, set back to 'No Filters' and proceed to step 3.
  3. Search for "Shutting down" or "Thread exiting"- In a crash scenario, the root cause is displayed around these words.
  4. Narrow down the problematic code using breakpoints. There's many ways to do this, but I prefer to set a breakpoint on any "major event" (OnCreate, Service, Calls, Catch Exception, etc) and run through each one until I find a major event that is never reached, but should be. Then I adjust the breakpoints a little more each time to narrow it down more.
  5. Give some extra attention to nearby Threads/Runnables, as these are often the culprits of mystery errors (infinite loops, deadlock, etc.). Place a breakpoint at each line in the run() method if you have to, and see where it hangs/fails.
Community
  • 1
  • 1
user3829751
  • 712
  • 7
  • 20