• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting Null Exception Pointer when trying to access an ArrayList<File>

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm writing a simple program that has a number of different labels where I display images (jpgs). The program allows you to choose a directory with pictures in it and then click a menu item to read that directory and load a single picture in each label. That part works. However, I also have a button within each JPanel (that holds each JLabel that holds the image) that, when you click on it, should move the picture from one directory to another. However, that's the part that doesn't work. Here are some code bits (figured that would be easier than posting the full code but please tell me if it's best to do otherwise:

Declares variable pictureNamesArrayList within the class itself so I can access it anywhere in the program (at least that was my intention)


Constructor ..


Then code to create the JPanels to hold to pictures and buttons I want:


Code that executes when the "Load" menu item is chosen. This works so I know pictureNamesArrayList is getting loaded correctly and has values in it at this point



Lastly, the code called when the "Archive" button is clicked and the part that is returning the following error: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException


I looked up what the error means and found that it means Java is pointing to a Null. I'm assuming that is the pictureNamesArrayList at this point but I can't figure out what it is null. Any help would be appreciated.
 
Bartender
Posts: 5465
212
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A wild first guess: you define pictureNamesArrayList in two places: as an instance field in your first code, and as a local variable in the method 'loadPicture'. The instance field looks therefore to be uninitialized, so that might cause the NPE.
 
reply
    Bookmark Topic Watch Topic
  • New Topic