About exception understanding in Java code

Source: Internet
Author: User

By using the Java language for Android development, you often encounter some anomalies, and want to use a way to find a child in a simple understanding of the transformation.

1. java.lang.NullPointerException ( null pointer exception )
An uninitialized object or an object that does not exist is called

Java.lang.FileNotFoundException

file not found exception

Simply said is not to find the child, the solution is to have a child, no child will have a (create object), the child needs to be alive (no null value to judge the case, to assign values to the object),

Where the child is clear (the object should be quoted correctly, the address is correct) so that the basic child should be able to find it.

2. Java.lang.ClassNotFoundException  

The specified class does not exist (or the specified variable does not exist, the specified method does not exist, the main reason is that it is not created, or the address (name) is not created, and is not found)

Simply say you're looking for a child with 3 eyes, because there's no such type of child, so you can't be sure you can have a three-eyed child (you can't create an object). Workaround, first determine whether the child is 3 eyes, if it is a child of 2 eyes, is a normal child, as long as the reference to human can be created (existing classes can be created object)

3. Java.lang.NumberFormatException

string conversion to numeric exception

java.lang.ClassCastException

data type Conversion exception

Simply put, you have to turn a tree into your child, because they are of different types, so they cannot be converted, the solution is either to not convert, or to find the right method of conversion, or to create their own conversion methods (like if you are a scientist, you can invent a way to convert trees into human beings, hehe)

4. Java.lang.IndexOutOfBoundsException

array subscript out of bounds exception

   In short, you put your child in your bedroom, you are in the bathroom, you look for the scope of the error, so can not find, the solution is clear scope, only within the scope of the search

5. Java.lang.IllegalArgumentException

parameter error for method

In short, you give your child a bottle to eat, because your child eats food (the type of incoming parameters), and the plastic bottle is not food, so the child eats the bottle with an error, the solution is to first identify what type of food the child is eating (here is foods), make sure you give the child food (determine the type of incoming parameters), The Act of Feeding food (method of invocation).

6. Java.lang.IllegalAccessException

No access rights

Simply put, you are looking for a child in someone else's house, because you have no right to enter someone else's home, (no access) so it is wrong, solution (1) Do not enter other people's home (no access to access) (2) after the consent of others, access to other people's homes (modify access rights, have access rights)

7. Java.lang.ArithmeticException

Mathematical Operation Anomaly

The simple thing is that you just let your child disappear out of thin air because it does not conform to the laws of physics (which do not conform to mathematical rules), so error

There are some other exceptions, there is time to continue to tidy up, about these anomalies are only their own understanding, there is not in place to hope and all of you to communicate together, progress.



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

About exception understanding in Java code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.