Last active
October 15, 2017 20:19
-
-
Save ClassCubeGists/5ea0ce430f2c76f3e0999f257a711860 to your computer and use it in GitHub Desktop.
Code samples for a quick demo on Java NullPointerException https://clsc.be/12
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
public class Demo { | |
private ArrayList<String> words; | |
public Demo( String[] theWords ) { | |
for (String s: theWords) { | |
words.add(s); | |
} | |
} | |
public static void main( String... args ) { | |
Demo d = new Demo( "here are some words" ); | |
System.out.println( words ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
public class DemoFixed { | |
private ArrayList<String> words; | |
public Demo( String[] theWords ) { | |
words = new ArrayList<>(); | |
for (String s: theWords) { | |
words.add(s); | |
} | |
} | |
public static void main( String... args ) { | |
DemoFixed d = new DemoFixed( "here are some words" ); | |
System.out.println( words ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment