Common Errors while Developing Android Application




  • NullPointer error
    1. when i use un initialized variable or object we are creating. (Java)
    2. when we use some layout out view that is not in xml what we set in context.(Android)

  • ClassCast Exception
    • when a program attempts to cast a an object to a type with which it is not compatible. (eg: when i try to use a linear layout which is declared as a relative layout in xml layout).

  • StackOverflowError
    • it can also occur in correctly written (but deeply recursive) programs.(java and android)
    • when a program becomes infinitely recursive.
    • we create layout (deep and complex) that exceeds that stack of platform or virtual machine . recursive or too much of layout will create Stack overflow error in Android
    • Too many inner layouts.

  • ActivityNotFoundException: Unable to find explicit activity class exception
    • The activity is not declared in manifest.

  • Android securityException
    • You need to declare all permission in the application Manifest that your application check this link (internet, access to contact,gps,wifi state,write to SDCard, etc).

  • OutofMemoryError
    • when a request for memory is made that can not be satisfied using the available platform resources . mainly using bit map, gallery , etc.

  • Application Not Responding (ANR)
    • Mainly comes when you are making network function,or some long process.
    this will block UI Thread so user can not do any work. to avoid ANR read this & this
This are thing i mainly get while creating Android Project.
  • Try to use Try - Catch block in All Place of program. Dont leave your catch block empty as this can hide errors:
Yes:
 try{
// try something
} catch (Exception e) {
Log.e("TAG", "Exception in try catch", e);
return false;
}
return true;
No:
  try{
// try something
} catch (Exception e) {
return false;
}
return true;

Use proper Naming conversion for all variable and ID's in Layout.*

 one article from net it contains some error now i am adding that alos if it have redundancy please forgive me.

Issue : My previously nice RelativeLayout is making an ugly heap or some elements aren't visible anymore...What's going on ??? I just moved an element in it... Solution : Never forget that in a RelativeLayout, elements are referenced and placed in relation to their neighbours. Maybe there is something wrong in the hierarchy of relationship between your element. Try opening the outline view in Eclipse and clicking each element to see where there is a rupture.

Issue : Circular dependencies cannot exist in RelativeLayout Solution : You have probably written the same dependency in two different way. For instance an ImageView as the attribute android:layout_toRightOf a TextView and the TextView has android:layout_toLeftOf the ImageView. Only one of them is necessary
Issue : I wrote a style for one of my view/layout, but when I apply it in my xml, I have no display in the layout viewer of Eclipse Solution : Unfortunately, this seems to be a bug of the android ADT, I reported it but no news so far. Anyway, no panic, styles are working well, but they aren't displayed properly in Eclipse. Just build the app and launch it on the emulator or phone and you will see if everything is fine or not.

Issue : Toast is written properly but nothing is displayed Solution : This is a common error of use : just add the .show() method to show the Toast and see if it is working well

Issue : I tried to display a String from strings.xml but I just had a number like 0x7f060001 Solution : This is not a bug, just a display due to the way android deals with resources. When you want to retrieve a resource, you have to use a method like getString(R.id.something), getDrawable, …Otherwise, you just display the reference written in the R class

Issue : Some change in code doesn't have any effect in the application Solution : there are 2 options, either you have forgotten something like the .show() of the Toast, or the emulator is not updating properly your application. In that case, you have to check the option “Wipe user Data” in your launch configuration of the emulator in Eclipse.

Issue : How to display borders on my table? Solution : There is no direct way to do that in android, you have to use a trick :http://www.droidnova.com/display-borders-in-tablelayout,112.html

Issue : the emulator is writing in japaneese withtout you having changed any parameter Solution : This happens sometimes, quite easy to fix, just long click in any EditText field, and change the input type to what you want

Issue : I can't get the Context Menu to appear in the emulator Solution : long click on emulator does not seem to register on every kind of view, you have to push the button in the center of the 4 directionnal arrows

Issue : I'm following a tutorial about map route but I can't get it work, android does not find a package Solution : You might have been following a tutorial written for 1.5 SDK. At this time, there was a package to display route in android, but it was removed in the next SDK and is not available anymore. It just not possible anymore. There seems to be a trick with KML files but nothing official

Issue : Sending coordinates to the emulator gives wrong position Solution : ensure that you wrote the coordinate like 51.16548 and not 51,16548 nor 5116548

Issue : Only the original thread that created a view hierarchy can touch its views. Solution : You must have tried to update a view content from another thread than the UI thread. 2 options to patch this : either create a handler in your UI thread and post your Runnable to this handler OR use the method runOnUIThread to run the lines of code that are doing the update


Issue : accessing localhost 127.0.0.1 doesn't work Solution : it works, you are just not doing it the right way : use 10.0.2.2

Source

Happy Coding!!!

Common Errors while Developing Android Application Common Errors while Developing Android Application Reviewed by D Kshetri on 1:25 AM Rating: 5

No comments:

Powered by Blogger.