NullPointerException the cause of the abnormal??

Source: Internet
Author: User

The so-called null pointer exception is because the property or method is called with null (NULL).   Null means there is no such object, since there is no such object, then to invoke his properties and methods, it will report an exception.   <--mainly for the following reasons: 1, the use of uninitialized variables (although declared) 2, the use of uninitialized objects (although already declared) 3, the use of the keyword or existing class name variable object methods or class names.   This exception is thrown when an application attempts to use null where the object is needed.   <--This scenario includes invoking an instance method of a null object.   A field that accesses or modifies a null object.   Use NULL as an array to get its length.   Use NULL as an array to access or modify its time slice. Throws null as the Throwable value. (The above points to understand, and then look at your code, will definitely find out)

Null pointer exception.

General report Java.lang.NullPointerException for the following reasons: 1. String variable uninitialized; 2. An object of the interface type is not initialized with a specific class, for example: 3. List lt; Will error 4. List lt = new ArrayList (); You will not get an error of 5. When the value of an object is empty, you are not judged to be empty. You can try adding a line of code to the following code:

if (rb!=null);

Objects of type string can be judged as follows

if (rb!==null&&! "". Equals (RB)) ...

Of course, you can do more than one judgment, whether it is not an empty string

if (rb!==null&&! "". Equals (Rb.trim ()))

NullPointerException the cause of the abnormal??

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.