A solution for 'source not found' in Eclipse?

Common bugs/problems with the Android SDK the Emulator and the ADT-Plugin.

A solution for 'source not found' in Eclipse?

Postby Marchu » Wed Oct 15, 2008 1:16 am

I have looked for a solution since i started with Eclipse (a few weeks ago), for the folowing, in my eyes strange debugging.

I know the Android package doesn't included the source code, so that's why i get a 'source not found' error in Eclipse, everytime i debug the code and there is something wrong.
But it is in this way, so dificult to get the point where the orginal error happens in the main code, that debuging is getting harder when this code is growing bigger.

I just want the point, where the error shows up in the code i wrote.... or what the original error is. (a source not found error says nothing)
Instead i must use breakpoints, and follow the code step for step, to find the point where the error comes up.
But this takes lot of time.

I have used many develop platforms/programs, but this behaviour is so strange, that i wonder if i'am doing something wrong. Or at least have some settings wrong within eclipse.

I have searched this forum and the internet, but still no solution found.
If someone knows a better way to debug, i will hear that gladly.

Thanks.
Marchu
Junior Developer
Junior Developer
 
Posts: 22
Joined: Sat Sep 27, 2008 4:11 pm
Location: Netherlands

Top

Postby Anm » Fri Oct 17, 2008 9:40 pm

Not really a solution, but what I've found helpful:

First off, make sure you have DDMS running, or the Eclipse logcat window visible. This is where System.out and the Log framework are output.

Secondly, Wrap all the code of every externally called method (event handles, app/activity phase handlers, etc.) with a try/catch block similar to the following:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. try {
  3.  
  4.    // your code
  5.  
  6. } catch( RuntimeException error ) {
  7.  
  8.    Log.e( TAG, "ERROR: "+Errors.toString(error) );
  9.  
  10.    throw error;
  11.  
  12. } catch( Error error ) {
  13.  
  14.    Log.e( TAG, "ERROR: "+Errors.toString(error) );
  15.  
  16.    throw error;
  17.  
  18. }  
  19.  
  20.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


where Errors is a little utility class:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class Errors {
  3.  
  4.     /** Returns error as string with complete stack trace of all causes */
  5.  
  6.     public static String toString( Throwable error ) {
  7.  
  8.             StringWriter sw = new StringWriter();
  9.  
  10.             PrintWriter pw = new PrintWriter( sw );
  11.  
  12.            
  13.  
  14.             printError( error, pw );
  15.  
  16.            
  17.  
  18.             pw.flush();
  19.  
  20.             String s = sw.toString();
  21.  
  22.             return s;
  23.  
  24.     }
  25.  
  26.    
  27.  
  28.     /** Prints the error to the PrintWriter with complete stack trace of all causes */
  29.  
  30.     public static void printError( Throwable error, PrintWriter pw ) {
  31.  
  32.         pw.println( error );
  33.  
  34.         error.printStackTrace( pw );
  35.  
  36.        
  37.  
  38.         Throwable cause = error.getCause();
  39.  
  40.         if( cause!=null ) {
  41.  
  42.                 pw.println();
  43.  
  44.                 pw.print( "CAUSE: " );
  45.  
  46.                 printError( cause, pw );
  47.  
  48.         }
  49.  
  50.     }
  51.  
  52. }
  53.  
  54.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
Anm
Freshman
Freshman
 
Posts: 7
Joined: Wed Oct 15, 2008 8:21 am

Postby Marchu » Tue Oct 21, 2008 1:28 am

Thank you for the advice.

I use now more try - catch constructs, at least when developing.
This takes more resources, so i'am not real fund of those constructs, and maybe i remove some when the application is ready.

Also i have now set in the catlog screen (inside eclipse debugger), to show only the errors. I discovered this are also the ones the catch construct throws.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. catch (Exception e) {      
  2.  
  3.                   e.printStackTrace();
  4.  
  5.             }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4

This make it somewhat easier to know the error.
And from the error text i now have a clue where the error throws.

Cheers
Marchu
Junior Developer
Junior Developer
 
Posts: 22
Joined: Sat Sep 27, 2008 4:11 pm
Location: Netherlands

Postby Anm » Tue Oct 21, 2008 4:25 am

My understanding of the JavaVM (not that it applies to the Dalvik) is that there is almost no cost to using a try/catch block unless an exception is thrown.

You can limit the inclusion of the "ERROR: " string in every class that uses this construct by pushing this String to the toString(Throwable) method. If you really worry about resources, run your .class files through a code obfuscator, as it will short the method names of private methods and fields (which are strings in the classes). Not sure how well it work with Android post-processor.

One other thing I wanted to mention. There was an error in my code above that limits the printout to a single cause depth. In printError(..), it should read:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.      Throwable cause = error.getCause();
  3.  
  4.      while( cause!=null ) {
  5.  
  6.           pw.println();
  7.  
  8.           pw.print( "CAUSE: " );
  9.  
  10.           printError( cause, pw );
  11.  
  12.  
  13.  
  14.           cause = cause.getCause();
  15.  
  16.      }
  17.  
  18.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4

(rather than the prior if(..) statement.

Anm
Anm
Freshman
Freshman
 
Posts: 7
Joined: Wed Oct 15, 2008 8:21 am

Top

Return to SDK/ADT/Emulator Problems

Who is online

Users browsing this forum: No registered users and 4 guests