summaryrefslogtreecommitdiff
path: root/content/digarden/20221028223544-nullpointerexception.org
blob: 24d966eedb4957caa2576748b9534fb9860e2bd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
:PROPERTIES:
:ID:       f346dcfa-5575-4aab-a245-36ff96266611
:END:
#+title: NullPointerException
* NullPointerException
Thrown when an application attempts to use null in a case where an
object is required. These include:

- Calling the instance method of a null object.
- Accessing or modifying the field of a null object.
- Taking the length of null as if it were an array.
- Accessing or modifying the slots of null as if it were an array.
- Throwing null as if it were a Throwable value. 

https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it

NullPointerExceptions are exceptions that occur when you try to use a
reference that points to no location in memory (null) as though it were
referencing an object. Calling a method on a null reference or trying to
access a field of a null reference will trigger a NullPointerException.

#+begin_src java
  public class Example {
    public static void main(String[] args) {
        Object obj = null;
        obj.hashCode();
    }
}
#+end_src