question about debug on Eclispe

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

question about debug on Eclispe

Postby Bule » Tue Mar 29, 2011 11:35 pm

Hi all,
I've started to develop for android Platform after 2 years of experience in C# on Visual Studio.

I am following some tutorials and I don't have to much problem with the new environment.

But the following things is strange for me :
I put an error in my program starting an Exception in android functions the application ends but Eclipse doesn't tell to me where the error is ...

In c# application Visual studio directly jumps to the right line of code about the exception...

If i put a try catch on the "bad" code I can only see that the Exception object is null..so not very useful :(

The only thing that Eclipse told to me is the following message : "source not found". Searching the web I found that an explanation is that Android SDK doesn't have the source code include so I have to download it.

I ask if there is an other way or if I missing something because I think is quite obiuvs that you must see the line of the error in debug mode or the type of the exception was raised....

PS I am using Windows 7 as OS and Eclipse HELIOS

Best regards.
Bule
Freshman
Freshman
 
Posts: 8
Joined: Tue Mar 29, 2011 5:17 pm

Top

Re: question about debug on Eclispe

Postby jumpoutofatree » Wed Mar 30, 2011 2:43 am

I'm not very sure what you're referencing to as I haven't worked with visual studio in years, but the best way for error checking in my opinion is Log.w(String,String) there will show up in the log of the debugger and give you an idea where the code is crashing. There are other Log functions as well you could look into. Hope that helps mate.
jumpoutofatree
Junior Developer
Junior Developer
 
Posts: 17
Joined: Tue Mar 23, 2010 4:48 pm
Location: Gainesville, Florida

Re: question about debug on Eclispe

Postby raj_J2ME » Wed Mar 30, 2011 8:30 am

For debugging the project you can follow the link below,
http://www.vogella.de/articles/EclipseDebugging/article.html#usedebug

Though this shows the debugging for the Java App, however it can be done for the android too.
Thanks with Regards,
Raj - The Kernel
raj_J2ME
Master Developer
Master Developer
 
Posts: 311
Joined: Tue Feb 15, 2011 7:40 am
Location: The Capital of India,

Re: question about debug on Eclispe

Postby Bule » Wed Mar 30, 2011 4:27 pm

Hi all and thanks for quick responses.

Log.w .. I know this command but the problem is that when an error occurs calling a function about the android SDK the exception is null ...so the Log.w() command doesn't print anything useful :(

About the debugging link from raj_J2ME this is very clear but it seems that the debug dowsn't work very well about android exceptions

I'll try to better explain my opinion , even if it could be wrong :

- if I put this code
int a = 10;
int b = 0;
int c = a/b;

the debug and the log.w() tell me that there is a divide by zero Exception and it show me the right line of error, 'casue , I think , the error is about Java core..

if i put this code
try
{
Button b = (Button)findViewById(R.id.Textview);
b.isPressed();
}
catch (Exception error)
{

}

I get the exception on line b.isPressed (exception found with breakpoint ) because the cast to Button is not correct : Textview is not a Button ;)

but the exception error is null ...

this is strange for me , probbaly I am worrying for nothing and common errors in developing android application is on java core functions and not in android SDK function but it seems strange to me 'cause you use a lot of android specifics function and object ...
Bule
Freshman
Freshman
 
Posts: 8
Joined: Tue Mar 29, 2011 5:17 pm

Re: question about debug on Eclispe

Postby jumpoutofatree » Wed Mar 30, 2011 5:04 pm

I could be wrong, but Button class is inherited from TextView so a Button is a TextView but a TextView isn't a button.
jumpoutofatree
Junior Developer
Junior Developer
 
Posts: 17
Joined: Tue Mar 23, 2010 4:48 pm
Location: Gainesville, Florida

Re: question about debug on Eclispe

Postby Bule » Wed Mar 30, 2011 5:38 pm

yes I think so and this the cause of the exception (I created the Exception ad hoc)..but the question isn't the kind of the exception ..the question is that Eclipse seems not to be able to show me where the Exception is and what kind of exception is ...
Bule
Freshman
Freshman
 
Posts: 8
Joined: Tue Mar 29, 2011 5:17 pm

Top

Re: question about debug on Eclispe

Postby jumpoutofatree » Wed Mar 30, 2011 7:28 pm

I'm sorry if i'm just confusing you more, but you can always just start logging different lines and which ever line doesn't output you'll know exactly where it stops at. I will have to say that android in my experience (i could be a nub) but isn't nearly as easy to debug as regular java. I live and die by my Log.w. Try logging different aspects of what you think maybe crashing, for example array.size(), stack.peek(), etc type things ... Is that the exact code you're trying to run?
jumpoutofatree
Junior Developer
Junior Developer
 
Posts: 17
Joined: Tue Mar 23, 2010 4:48 pm
Location: Gainesville, Florida

Re: question about debug on Eclispe

Postby Bule » Thu Mar 31, 2011 8:00 am

Yes you are right about logging different line but you know this operation is quite long...I'll hope that it was possible to catch a general Exception in order to find the Exception when and where it comes...

about my error is a try so I know that the Exception is about the wrong cast but I'd like that EClipse tell me this ...as for istance Visual Studio done with C# ...and for istance as Eclipse done when I make some errors using Java core functions ..

this is quite strange for me I don't know if I missing something :(
Bule
Freshman
Freshman
 
Posts: 8
Joined: Tue Mar 29, 2011 5:17 pm

Re: question about debug on Eclispe

Postby raj_J2ME » Thu Mar 31, 2011 1:22 pm

Two quick suggestion:

1. I guess all the exceptions/errors are printed inside the Logcat, did you check/try it?
2. When you are saying that you got the error object of exception inside the catch block is null, and you are not getting the occurred exception inside the catch, however this is working fine for me.
here is the code:

Code: Select all
          try{
          button = (Button)findViewById(R.id.TextView01);
          button.setOnClickListener(new View.OnClickListener() {
            
            @Override
            public void onClick(View v) {
               // TODO Auto-generated method stub
               
            }
         });
          }catch(Exception e){
             System.out.println("inside the button catch : "+e.toString());
             
          }
Thanks with Regards,
Raj - The Kernel
raj_J2ME
Master Developer
Master Developer
 
Posts: 311
Joined: Tue Feb 15, 2011 7:40 am
Location: The Capital of India,

Re: question about debug on Eclispe

Postby Bule » Fri Apr 01, 2011 9:51 am

Hi raj_J2M thanks for help,
I try your code ..which the same of mine ... and when I use Eclipse Debug I have that e is null..and Eclipse than show me a screen with Source not found info and a button with "Edit Source lookup path"
..and nothing written in the LogCat window.

in your try you see the logcat message ?
perhaps do you have the sdk source code installed ?

Ps I am debugging on emulator ..
Bule
Freshman
Freshman
 
Posts: 8
Joined: Tue Mar 29, 2011 5:17 pm

Re: question about debug on Eclispe

Postby kevat_patel » Tue Apr 05, 2011 7:52 am

put your code
try{

}catch(Exceptiorn e){
e.printStackTrace();// display error information in Locget with debug mode of eclipse
}
kevat_patel
Developer
Developer
 
Posts: 46
Joined: Fri Mar 25, 2011 6:59 am

Re: question about debug on Eclispe

Postby Bule » Tue Apr 05, 2011 5:49 pm

Hi kevat_patel,
the problem is that for me the variable "e" is null...
Bule
Freshman
Freshman
 
Posts: 8
Joined: Tue Mar 29, 2011 5:17 pm

Re: question about debug on Eclispe

Postby Bule » Thu Apr 07, 2011 8:16 am

Hi all,
does anybody have this problem ?
Google around I see that a possible solution is to install the SDK source code but this solution seems quite hard for me ...
probably my problem is only about Emulator ? and if you debug the program directly to device there isn't this problem ?

Thanks
Bule
Freshman
Freshman
 
Posts: 8
Joined: Tue Mar 29, 2011 5:17 pm

Re: question about debug on Eclispe

Postby huascar82 » Tue Apr 12, 2011 10:49 pm

You'll have the same issue. Its a big annoyance for me as well. I've only done vb programming before 2 weeks ago. I can tell you though. Once you come up with an error and you click thru the green play looking button, and you come up with the fc alert in your emulator, you click past the alert, you can then look at logcat and you'll see an error log for your fc. You'll need to look thru it, but usually there will be one or 2 lines relevant to your code. Double click it and it will take you to the line in your class.

Also, in the try catch above, e is the exception object not your button object. The try catch will prevent the fc in the em but will provide better info in logcat. I was having an issue that I had no idea what it ws until I used try catch and was able to actually get a clear message, probably from the android plugin asking me to check to make sure I added my activity to my manifest.

Hope this helps.
huascar82
Freshman
Freshman
 
Posts: 6
Joined: Tue Apr 12, 2011 10:02 pm

Re: question about debug on Eclispe

Postby Bule » Wed Apr 13, 2011 2:02 pm

Hi huanscar82, thanks for your post,
but I can't understand what do you mean for "fc".

Then I know that "e" is the Exception object and the strange thing for me is that this object is null and it doesn't have any infos about the error.
A I written also the log cat doesnìt show any useful informations to understand where the error is.
Bule
Freshman
Freshman
 
Posts: 8
Joined: Tue Mar 29, 2011 5:17 pm

Top
Next

Return to SDK/ADT/Emulator Problems

Who is online

Users browsing this forum: No registered users and 7 guests