wood burning stoves 2.0*
The moose likes Applets and the fly likes ArrayList not instantiating when Applet loads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "ArrayList not instantiating when Applet loads" Watch "ArrayList not instantiating when Applet loads" New topic
Author

ArrayList not instantiating when Applet loads

Chad Clites
Ranch Hand

Joined: Aug 16, 2005
Posts: 134
This is not a problem so much as an observation that I don't understand. I am working with a JApplet in Netbeans, and I have an Arraylist as a Global variable, and I created it simply by using ArrayList aa;. I have a loop that loads the ArrayList, and I kept getting a null pointer error. Once I changed the ArrayList constructor to ArrayList aa= new ArrayList();, the null pointer error goes away.

I've been looking through the docs, and I can't find why this is. I thought all objects declared globally just used a default constructor? Is it different for applets?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41155
    
  45
I thought all objects declared globally just used a default constructor?


No, object are not instantiated automatically, and will always be null. Only primitives get assigned a default value. What piece of code gave you the idea that objects were instantiated automatically?


Ping & DNS - my free Android networking tools app
Chad Clites
Ranch Hand

Joined: Aug 16, 2005
Posts: 134
I don't have one good reason to think that, actually. I also can't think of any time I was presented with the fact that objects were null. Probably a by-product of too many hours in an IDE and not enough in a text editor, not that it is any excuse.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: ArrayList not instantiating when Applet loads
 
Similar Threads
using TreeSet TreeMap with Strings And Integers Problem
Khalid Chapter 2 ...
NULL POINTER EXCEPTION
constructor..
fwd or backward ,don't know which reference??