1 / 18

Mobile Programming Lecture 3

Mobile Programming Lecture 3. Debugging. Lecture 2 Review. What widget would you use to allow the user to enter a yes/no value a range of values from 1 to 100 What's the benefit of a Relative Layout over LinearLayout? How many ways can you set an event listener?. Lecture 2 Review.

carys
Download Presentation

Mobile Programming Lecture 3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Mobile Programming Lecture 3 Debugging

  2. Lecture 2 Review • What widget would you use to allow the user to enter • a yes/no value • a range of values from 1 to 100 • What's the benefit of a RelativeLayout over LinearLayout? • How many ways can you set an event listener?

  3. Lecture 2 Review • How do you make the android:inputType attribute of an EditText both textCapCharacters and and textMultiLine? • Why should you use a @string resource for TextViews instead of hardcoding the string? • If you use the same android:onClick value for multiple views, how do you determine which one was clicked?

  4. Agenda • Debugging using Toast ... • LogCat • Debug Perspective • Importing existing projects into Eclipse • Lab debugging assignment

  5. Debugging using Toast ... • A Toast is an easy way to debug your app • ... sometimes

  6. Try not to debug using Toast! • it's slower • especially if you're using multiple Toasts • it doesn't persist • after the Toast is gone, you may not have seen all of the debug information, then you'll have to run it again • sometimes the code for a Toast will be correct, but the Toast just won't show! • depends on the state of the application

  7. Debugging - LogCat • LogCat shows the stack traces, diagnostic information from the operating system. • You can use LogCat in Eclipse easily: • Log.i("HelloWorldActivity", "This line has been executed"); This is the message Tag This is the message

  8. Debugging - LogCat Log.i("HelloWorldActivity", "This line has been executed"); Log.i("HelloWorldActivity", "Value of x = " + x);

  9. Debugging - LogCat Log.i("HelloWorldActivity", "This line has been executed"); Log.i("HelloWorldActivity", "Value of x = " + x); This is the message. Prints the value of x to the Log

  10. Debugging - LogCat A good convention is to declare a TAG constant in your class

  11. Debugging - LogCat private static final String TAG = "HelloWorldActivity"; Log.i(TAG, "This line has been executed"); Log.i(TAG, "Value of x = " + x);

  12. Debugging - LogCat • Open the LogCat view if it's not already open in Eclipse • Window > Show View > LogCat • Under Saved filters, click the + button to add a new filter • Enter the following (modify to match your app) • Filter Name: HelloWorldActivity • by Log Tag: HelloWorldActivity • Click OK • Your debug messages should now show up • If they're not showing up, double check your filter (or advance a few slides in this presentation)

  13. Debugging - LogCat You can view LogCat information up until you close Eclipse (or probably until you run out of memory dedicated to LogCat)

  14. Debugging - Debug Perspective Another way to debug is by using breakpoints, which you may already be familiar with from an IDE other than Eclipse • Add breakpoints to lines in your code where you want to pause your program • To start debugging, you can do one of the following • press F11 • Run > Debug If your application gets to your breakpoint, it will pause there

  15. Debugging - Debug Perspective • If it asks whetheryou want to switch to Debug Perspective, say yes • In the Expressions View of the Debug Perspective, you can add variables to see what their values are at the breakpoint • e.g., if you have int x somewhere in your code, try adding x to • You may have to open the view first • Window > Show View > Expressions • Buttons in the Debug View allow you to continue or step through the rest of the code • Resume, Step Into, Step Over, etc

  16. Exporting projects from Eclipse To export a project from Eclipse • Right click your project > Export > General > Archive File • Next • Select your project if necessary • Options > Save in tar format preferably (zip will work as well) • Browse ... • Finish Submit your homework assignments and projects in these formats

  17. Importing projects into Eclipse Most code examples that I post will be .tar (or .zip) archive files To import an existing project into Eclipse • Download the archive file • Navigate to File > Import ... > General > Existing Project into workspace • Choose "Select archive file" • Browse for the downloaded file and select it • Finish I may include a README file in the root directory with instructions that you need to follow

  18. References • The Busy Coder's Guide to Android Development - Mark Murphy • Android Developers • The Mobile Lab at Florida State University

More Related