Message from @Paragram Slide - AZ

Discord ID: 495337869527744523


2018-09-28 20:48:49 UTC  

okay that exception is fixed I think

2018-09-28 20:49:01 UTC  

maybe let's see if we can do anything with one more thing

2018-09-28 20:49:26 UTC  

is this linked list or tree node?

2018-09-28 20:49:31 UTC  

linked list

2018-09-28 20:49:41 UTC  

huh I get a null pointer exception from somewhere else, too

2018-09-28 20:49:47 UTC  

```java
------------------testAddLast()----
Exception in thread "main" java.lang.NullPointerException
at MyLinkedList$ListNode.access$2(MyLinkedList.java:11)
at MyLinkedList.add(MyLinkedList.java:205)
at MyLinkedListTester.testAddLast(MyLinkedListTester.java:42)
at MyLinkedListTester.main(MyLinkedListTester.java:214)
```

2018-09-28 20:50:17 UTC  

```java
public static void testAddLast() { //passed
System.out.println("------------------testAddLast()----");
init();
list3.add("A");
System.out.println(list3);
list3.add("B");
System.out.println(list3);
list3.add(null);
System.out.println(list3);
list3.add("C");
System.out.println(list3);
drawLine();
}
```

2018-09-28 20:51:10 UTC  

```java
//Add the object e to the end of this list.
// it returns true, after e is successfully added.
public boolean add(Object e) {
ListNode newNode = new ListNode(e);
newNode.next = null;
get(this.size - 1).next = newNode;
this.size++;
return true;
}
```

2018-09-28 20:51:17 UTC  

any glaring problems here?

2018-09-28 20:51:55 UTC  

that get() could return null

2018-09-28 20:52:16 UTC  

hmmm

2018-09-28 20:52:22 UTC  

any ideas on how to fix that?

2018-09-28 20:52:39 UTC  

after init()

2018-09-28 20:52:53 UTC  

how many nodes in list3

2018-09-28 20:53:04 UTC  

println after init()

2018-09-28 20:53:19 UTC  

4

2018-09-28 20:53:33 UTC  

what is size

2018-09-28 20:53:42 UTC  

should be 4

2018-09-28 20:55:09 UTC  

I see

2018-09-28 20:55:24 UTC  

list3.add("C") will throw

2018-09-28 20:55:51 UTC  

because last node was null

2018-09-28 20:56:27 UTC  

and when you get it... and attempt to set next

2018-09-28 20:56:34 UTC  

the data was null, not the node itself I think

2018-09-28 20:56:43 UTC  

ahh ok

2018-09-28 20:56:53 UTC  

it must be the size then

2018-09-28 20:57:11 UTC  

get(this.size - 1) is returning null

2018-09-28 20:58:54 UTC  

```
ListNode last = get(this.size - 1);
if (last != null) {
last.next = newNode;
++this.size;
return true;
}
return false;
```

2018-09-28 20:59:42 UTC  

thanks

2018-09-28 21:02:13 UTC  

this would only happen adding first node to list I would think

2018-09-28 21:02:18 UTC  

what is this class?

2018-09-28 21:02:22 UTC  

data structures?

2018-09-28 21:02:27 UTC  

or Java class?

2018-09-28 21:03:39 UTC  

Data Structures

2018-09-28 21:04:23 UTC  

I actually have a Java developer certificate but it was a long time ago so I have to relearn everything

2018-09-28 21:04:36 UTC  

Got it same time as I graduated high school

2018-09-28 21:04:38 UTC  

when I took that class we used C

2018-09-28 21:04:56 UTC  

1999 😉

2018-09-28 21:05:47 UTC  

Java was its own class back then - the OOP class

2018-09-28 21:13:02 UTC  

I had to take a 3 part Java series to get into this class

2018-09-28 21:13:10 UTC  

It was part of my certificate

2018-09-28 21:24:09 UTC  

nice