Download presentation
Presentation is loading. Please wait.
Published byDarcy Park Modified over 9 years ago
1
Mobile Programming Lecture 3 Debugging
2
Lecture 2 Review What widget would you use to allow the user to enter o a yes/no value o 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 o especially if you're using multiple Toasts it doesn't persist o 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! o depends on the state of the application
7
Debugging - LogCatLogCat LogCat shows the stack traces, diagnostic information from the operating system. You can use LogCat in Eclipse easily: o Log.i("HelloWorldActivity", "This line has been executed"); This is the message Tag This is the message
8
Debugging - LogCatLogCat Log.i("HelloWorldActivity", "This line has been executed"); Log.i("HelloWorldActivity", "Value of x = " + x);
9
Debugging - LogCatLogCat 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 - LogCatLogCat A good convention is to declare a TAG constant in your class
11
Debugging - LogCatLogCat private static final String TAG = "HelloWorldActivity"; Log.i(TAG, "This line has been executed"); Log.i(TAG, "Value of x = " + x);
12
Debugging - LogCatLogCat Open the LogCat view if it's not already open in Eclipse o Window > Show View > LogCat Under Saved filters, click the + button to add a new filter Enter the following (modify to match your app) o Filter Name: HelloWorldActivity o by Log Tag: HelloWorldActivity Click OK Your debug messages should now show up o If they're not showing up, double check your filter (or advance a few slides in this presentation)or advance a few slides in this presentation
13
Debugging - LogCatLogCat 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 o press F11 o Run > Debug If your application gets to your breakpoint, it will pause there
15
Debugging - Debug Perspective If it asks whether you 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 o 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 o 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 The Busy Coder's Guide to Android Development - Mark Murphy Android Developers The Mobile Lab at Florida State University
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.