Debug Application

To create a debug configuration for your application within Eclipse, choose Debug as , Debug Configurations.

Pick the Android project you want to debug, and then click OK. Once your application is running in the emulator or on a device, you can begin debugging it.

It will flash a message “waiting for debugger”..

On the top right-hand corner of Eclipse we have Java perspective and Debug perspective, we can switch between the two. The code execution will be shown in Debug perspective.

First, let's set a breakpoint in the code.The most common debugging features in Eclipse that you will need in order to step through your code are:

Step Into: Use this feature to move deeper into your code by moving into method code. Or Press F5 to step-into code.

Step Over: Use this feature to move to the next line of code on the same level as the previous one. Press F6 to step-over code.

Step Return: Use this feature if you are in the middle of stepping into a method, and are past the area of the method you wanted to inspect. The current method will finish up and you will pop up to the next line of execution after that method has returned so you can continue debugging. Press F7 to step-return.

Resume: Done with this little session of debugging and want the app to start running again Then use the Resume feature. Press F8 to resume running without stepping.

We can see the values for the variables and breakpoint In the right corner of eclipse or move over the coding and on variable.

One can review all Error in Emulator/Mobile and Console, LogCat and Error Log during Testing. There are frequent type of errors that appear and the same are mentioned below.

We will list down some error finding Tips and Technique.

A. Frequent type error appear.

    • Image name should have [a-z][0-9]. Special character or ‘-‘ are not allowed.
    • R.id can not be resolved.

B. Review  error in Show View->Console, Show View->Log Cat and Show View->Error Log.

    •  By viewing at error log one can diagnose the error easily on which line the error is appearing.

C. Debug Android Page and Classes.

    • Use Log.v()  at different place in code and view in log in verbose mode and monitor  execution steps.
    • Use Try/catch() to find errors.

 

Few cases are listed below

 

A. Frequent type of error reported on Emulator/Mobile while testing.
1.  Image name should have [a-z][0-9]. Special character or ‘-‘ are not allowed. The name of image file should only contain letters and numbers. Like “-“ used in file name  will through error as shown below  at  runtime.
2. Error like 'R.id can not be resolved' ( if there is no syntax error without red mark) . Such errors can be resolved as follows.
 
  • These are errors are mainly the R.id are not generated due to improper use of syntax.
  • Image name have “-“ and [a-z][0-9].
  • Correct the errors and clean and rebuild again. At times better cut some portion of xml code, save all, paste again, clean and build again. (This error is due to  R.id is already generated and is not built again or new one is not getting created).
 
 B. Review  error in Show View->Console, Show View->Log Cat and Show View->Error Log.
1. Review View->Console  Eg. For errors in xml file is shown below. Here the error is due to @color/black is not define at line no 18 of xml file.
 
2.  Review View->LogCat and Error log.
 
3. Check for error and line no. and try to find the type of error.
 
C. Debug Android Page and Classes.
1. Use Try/Catch to debug classes. An Example is show below.
public List<items> listjson(String jsondata)
{
List<items> listitems = new LinkedList<items>();
try
{
JSONObject jsonResponse = new JSONObject(jsondata);
JSONArray jsonMainNode = jsonResponse.optJSONArray("data");
for (int i = 0; i < jsonMainNode.length(); i++)
{
JSONObject jsonChildNode = jsonMainNode.getJSONObject(i);
String itemdesc = jsonChildNode.optString("item_short_desc");
items it = new items();
it.setId(Integer.parseInt(id));
it.setItem_short_desc(itemdesc);
listitems.add(it);
Log.v("getData>", it.getItem_short_desc().toString());
}
} catch (JSONException e) { Log.v(“Error Reported”,e.toString()); }
return listitems;
}

















2. Check Log.v for java files to see the values in log in verbose mode.
3. Debug classes using “ Debug as -> Debug on Server”.