• 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

problems with displaying..

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I'm trying to display a 3 x 3 grid made up of an array of 9 individual cell objects. I created two classes, one for each cell, and one for the whole board. So far, I can only display the board 'border'. When I try to invoke the method to draw each cell from the Board class, i get a null pointer exception error within the black dos window for some reason?? Would anyone care to take a look and give a little feedback? I would really appreciate it.

Here's the code:



Thanks
from BC
 
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Savanna,

Your problem lies in the Board constructor. You have instanciated TWO arrays of cells. One here:



and a second here:



The first one is an instance variable and the second one a local variable.

The one you are using in the drawBoard method is the instance variable which contains null values hence the null pointer exception you get.

Change your Board class to that:



Tell me if that helped,

Julien.
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic