Android Error List : 10 Common Errors and How to fix them

Here’s an Android programming tutorial to address the 10 most common mistakes Android developers make.

Enroll now for : Professional Android App Developement Training with Offer

1.ActivityNotFoundException

This exception is thrown when a call to startActivity fails because the Activity cannot be found. Usually, this means you forgot to declare the Activity in your Manifest.

2.Error converting byte to dex

If you are encountering this error, then try cleaning (Clean > Build Project) and rebuilding your project (Build > Rebuild Project). If this doesn’t work, then check that the package names you’re using in your classes, match the package name in your project’s Manifest.

3.ClassCastException

The ClassCastException error is related to Java’s type conversion feature, which allows you to cast variables of one type to another. You encounter a ClassCastException when you try to cast an object to a class of which it’s not an instance, for example attempting to cast a String to an Integer. To resolve this error, navigate to the section of your code represented in the error message and then check what object(s) are being cast here.

You can prevent the ClassCastException by using Generics, because Generics provide compile time checks and can be used to develop type-safe applications.

4.NullPointerException

When you are ready to use a reference that points to ‘no location’ in memory as though you are referencing an object. For example, maybe you are trying to call the instance method of a null object, or modifying the slots of null as though it’s an array.

To fix NPEs occurring in your project, make sure all your objects are initialized before you attempt to use them, and always verify that a variable isn’t null before you request a method or field from that object.

5.OutofMemoryError

This error occurs when your app makes a memory request that the system can’t meet. If you see this error message, then start by ruling out all of the most common memory management mistakes. Check that you’ve remembered to unregister all your broadcast receivers and that you’ve stopped all of your services; make sure you’re not holding onto references in any static member variables, and that you’re not attempting to load any large bitmaps.

Develope your own Android App Here

6.Install_Failed_Insufficient_Storage

This error may occur when you attempt to install your project on an Android Virtual Device (AVD) or physical Android device, and the device doesn’t have enough storage available.

If you’re using an AVD, close it and launch the ‘AVD Manager.’ Find the AVD you want to use, then click the ‘Edit’ icon. In the window that appears, select ‘Show Advanced Settings,’ scroll to the ‘Memory and Storage’ section and increase the amount of space available to your AVD. If you’re using a physical Android tablet or smartphone, then it’s time to spring clean your device to free up some space, for example, by uninstalling apps or clearing out some media files.

7.Only the original thread that created a view hierarchy can touch its views

This error occurs when you try to update a view from any thread other than the UI thread. To resolve this issue, make sure you perform any actions involving your app’s user interface on the UI thread only.

If you do need to access the UI thread from other threads, then you can use runOnUiThread.

8.NetworkOnMainThreadException

This exception is thrown when your application attempts to perform networking operations on its main thread, as long-running operations have a tendency to block the main thread and can result in an Application Not Responding error.

If your project throws a NetworkOnMainThreadException, then you have to move your Internet-related code to a separate thread. Alternatively, you can use IntentService or AsyncTask to wrap your network operations in a worker thread.

9.Too Many Field References

This message will be Shown whenever your project has more than 65646 references, as this one is the maximum number of references that can be invoked by a single dex bytecode file.

When it comes to fixing this error, you have two choices: either configure your app to use more than one dex file or reduce the number of references in your project.

10.Activity has leaked window that was originally added here

This error will be appear that you’ve exited an Activity before the dialogue has been dismissed. To resolve this issue,Ensure you call dismiss() to close any dialogues before exiting your Activity