Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Null pointer Exception

 
John Lockheart
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried creating an ADTList file, ArrayList file (which implements ADTList), then a test file. When running the test file I get null pointer exceptions.

ArrayList array = new ArrayList();

is this just making "array" of size 0? How can I create a default size within it's constructor inside ArrayList.java, then increase it's size if I choose to?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know what ADTList is, but you can specify an initial capacity for ArrayList in the constructor. It grows according to its own logic and doesn't give you any way to control that. I figure it's smarter than I am so that doesn't bother me.
 
John Lockheart
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've tried everything I can think of to do that. The only way I could even test my program was by importing java.util.ArrayList. So now the program doesn't even use my class I created. Like I said before, I created the ArrayList, ArrayList array = new Arraylist() and everytime I try and use my add or set method I get a null pointer Exception. Here's the class code:

 
Tom Joiner
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would make your class have a different name than ArrayList, perhaps MyArrayList, or ATDArrayList. It is very confusing (to a coder) to use the same class name as another class.

Then I would try stepping into your functions with your compiler and see what is happening. My guess is that you created an ArrayList and not your own class and are somehow invoking your class on a null pointer.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic