--java.lang.nullpointerexception of Java Exception resolution

Source: Internet
Author: User

1. Java.lang.NullPointerException "Null pointer exception"
There are several reasons for the general report java.lang.NullPointerException:
Usually, you refer to a new variable or the value is empty.
• The string variable is not initialized;
• An object of the interface type is not initialized with a specific class, such as:
List lt; Will error
List lt = new ArrayList (); You won't get an error.
• 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 && rb!= "")
Change to:
if (rb==null);
if (rb!==null&&rb!= "")
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 ()))

--java.lang.nullpointerexception of Java Exception resolution

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.