Home> Common Problem> body text

What is the cause of null pointer exception?

藏色散人
Release: 2023-02-14 13:59:05
Original
50293 people have browsed it

The reasons for the null pointer exception: 1. The new object is not instantiated, or an empty object is queried in the database; 2. When the object is null, the method owned by the object is called or caused by member variables.

What is the cause of null pointer exception?

#The operating environment of this article: windows10 system, thinkpad t480 computer.

The reason for the null pointer exception

1. The object you created new is not instantiated, or you go to the database to query an empty object, which is a null pointer

2. Null pointer exception NullPointer is nothing more than calling a method or member variable owned by the object when the object is null.

Solution:

It is possible to call When a variable is empty, it is best to make a non-empty judgment.

Related expansion introduction:

Null is a reserved value in calculation, used to indicate that the pointer does not refer to a valid object. Programs often use null pointers to represent conditions, such as the end of a list of unknown length or that some operation was not performed; this use of null pointers can be compared with the Nothing value in nullable and option types.

Null pointers should not be confused with uninitialized pointers: a null pointer is guaranteed to be compared with any pointer to a valid object. However, depending on the language and implementation, uninitialized pointers may not have any such guarantees. It may be equal to another valid pointer; or it may compare equal to a null pointer. It may do two things at different times.

The null character is usually represented as an escape sequence in a source code string character or character constant. In many languages, this is not a single escape sequence, but an octal escape sequence, the single octal digit being 0; therefore, '\0' cannot be followed by any digit 0 through 7; otherwise it is interpreted as a longer octal escape the beginning of the sequence. Other escape sequences that are found in use in various languages are \000, \x00, \z, or the Unicode representation \u0000.

The ability to represent the null character does not always mean that the resulting string will be interpreted correctly, as many programs will consider null to be the end of the string. Therefore, the ability to type it (in the absence of unchecked user input) creates a vulnerability known as null byte injection and can lead to security holes.

The empty character represented by a comma is ^@. On Windows, this can be done by holding down the Ctrl key and then pressing @ (this usually requires holding down ⇧ Shift and pressing the number 2 key at the same time).

The null character in documents is sometimes represented as a single em containing the letters "NUL" -width notation. In Unicode, there is a character with a corresponding character for the visual representation of the null character, the "null" symbol, U 2400 (␀), but not to be confused with the actual null character, U 0000.

Recommended: "Programming Video"

The above is the detailed content of What is the cause of null pointer exception?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!