Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 27th, 2005, 9:46 PM   #1
Xenon
Programmer
 
Join Date: Oct 2005
Location: UK
Posts: 31
Rep Power: 0 Xenon is on a distinguished road
Send a message via AIM to Xenon Send a message via MSN to Xenon Send a message via Yahoo to Xenon
Angry Urgent Java Help - Null Pointer Exceptions

First off Ill say this is a Uni Assignment, ive pretty much finished the assignment, only I keep getting Null Pointer Exceptions and its driving me crazy, the reason I say I need urgent help is that the assignment is due in in 10 hours, we were give 2 weeks to do it and I wont let all this work go to waste because of a stupid null pointer.

The assignment is basically to make a media management system for Photos, Sound Bites and Video Clips.

The media classes are all inherited from one class called MediaItem, there is a CatalogueArray (note: CatalogueArray NOT Catalogue) class which has all the add and delete functions, and also main class called MediaGui, there are also some other classes that arent used for anyhting yet.

Basically as youll se fom running the program, when you try to "Save" a media item, after filling in all the correct details, you will get a null pointer error, you will also get one when you load a library in and a few other things, I am having a huge time trying to sort this out and just cant do it, im hoping that a fresh set of eyes will spot it straight away.

I dont hold many high hopes for getting this done in time as it is very short notice, but if anyone can help me id be so unbelievably greatful.

I exported my whole project from eclipse into a file system and have uploaded it to my web space - http://www.dark-designs.co.uk/downlo...mentSystem.zip
Xenon is offline   Reply With Quote
Old Nov 27th, 2005, 10:30 PM   #2
2roll4life7
Programmer
 
2roll4life7's Avatar
 
Join Date: Aug 2005
Location: 0x0010 * 0x0091 + 0x0004
Posts: 65
Rep Power: 4 2roll4life7 is on a distinguished road
Quote:
Originally Posted by Xenon
First off Ill say this is a Uni Assignment, ive pretty much finished the assignment, only I keep getting Null Pointer Exceptions and its driving me crazy, the reason I say I need urgent help is that the assignment is due in in 10 hours, we were give 2 weeks to do it and I wont let all this work go to waste because of a stupid null pointer.

The assignment is basically to make a media management system for Photos, Sound Bites and Video Clips.

The media classes are all inherited from one class called MediaItem, there is a CatalogueArray (note: CatalogueArray NOT Catalogue) class which has all the add and delete functions, and also main class called MediaGui, there are also some other classes that arent used for anyhting yet.

Basically as youll se fom running the program, when you try to "Save" a media item, after filling in all the correct details, you will get a null pointer error, you will also get one when you load a library in and a few other things, I am having a huge time trying to sort this out and just cant do it, im hoping that a fresh set of eyes will spot it straight away.

I dont hold many high hopes for getting this done in time as it is very short notice, but if anyone can help me id be so unbelievably greatful.

I exported my whole project from eclipse into a file system and have uploaded it to my web space - http://www.dark-designs.co.uk/downlo...mentSystem.zip
I can't get it to compile on this computer I'm at but NullPointerExceptions occur when you declare an object but don't initialize it, then try to use that object. If you post the actual exception (and the line number that's given, I could be of more help).
__________________
#if 0 /* in case someone actually tries to compile this */
- libpng version 1.2.8 (example.c)

<Jim_McNeat> Is there like a way to put a compiler in "Just trust me on that one" mode?
2roll4life7 is offline   Reply With Quote
Old Nov 28th, 2005, 12:56 AM   #3
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 407
Rep Power: 5 xavier is on a distinguished road
Send a message via Yahoo to xavier
Maybe i'm just not seeing it, but in your CatalogueArray do you ever initialize numberOfMediaItems. Cause you keep comparing it but i can't see where you initialize it. Also the private MediaItem [ ] mediaItems;.

I'm probably waaay off
__________________
Don't take life too seriously, it's not permanent !
xavier is offline   Reply With Quote
Old Nov 28th, 2005, 5:23 AM   #4
Xenon
Programmer
 
Join Date: Oct 2005
Location: UK
Posts: 31
Rep Power: 0 Xenon is on a distinguished road
Send a message via AIM to Xenon Send a message via MSN to Xenon Send a message via Yahoo to Xenon
OK initialising numberOfMediaItems to 0 seems to of fixed some things, now when I load a library file in I ge this Null Pointer:

java.lang.NullPointerException
at mediaManagementSystem.CatalogueArray.displayAll(CatalogueArray.java:433)
at mediaManagementSystem.MediaGui$18.actionPerformed(MediaGui.java:556)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Xenon is offline   Reply With Quote
Old Nov 28th, 2005, 6:09 AM   #5
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 407
Rep Power: 5 xavier is on a distinguished road
Send a message via Yahoo to xavier
private MediaItem [ ] mediaItems  = new MediaItem[200];
initialize mediaItems also ... cause you work with it all the time , but i can't see where u're initializing it
__________________
Don't take life too seriously, it's not permanent !
xavier is offline   Reply With Quote
Old Nov 28th, 2005, 6:15 AM   #6
2roll4life7
Programmer
 
2roll4life7's Avatar
 
Join Date: Aug 2005
Location: 0x0010 * 0x0091 + 0x0004
Posts: 65
Rep Power: 4 2roll4life7 is on a distinguished road
Quote:
Originally Posted by Xenon
OK initialising numberOfMediaItems to 0 seems to of fixed some things, now when I load a library file in I ge this Null Pointer:

java.lang.NullPointerException
at mediaManagementSystem.CatalogueArray.displayAll(CatalogueArray.java:433)
at mediaManagementSystem.MediaGui$18.actionPerformed(MediaGui.java:556)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
You have an array of MediaItem objects that you have to make sure everyone is initialized before you can use the objects in your displayAll() function. I don't have time to check all your code for this right now, but I'm fairly confident that is your problem here.
__________________
#if 0 /* in case someone actually tries to compile this */
- libpng version 1.2.8 (example.c)

<Jim_McNeat> Is there like a way to put a compiler in "Just trust me on that one" mode?
2roll4life7 is offline   Reply With Quote
Old Nov 28th, 2005, 6:27 AM   #7
Xenon
Programmer
 
Join Date: Oct 2005
Location: UK
Posts: 31
Rep Power: 0 Xenon is on a distinguished road
Send a message via AIM to Xenon Send a message via MSN to Xenon Send a message via Yahoo to Xenon
Sorry, im not that great with Java as you may have noticed, how to I check everything is initialized
Xenon is offline   Reply With Quote
Old Nov 28th, 2005, 6:36 AM   #8
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 407
Rep Power: 5 xavier is on a distinguished road
Send a message via Yahoo to xavier
Quote:
Originally Posted by Xenon
Sorry, im not that great with Java as you may have noticed, how to I check everything is initialized
I think by hand ... Also i have a question :
public String displaySound() {
  	String result = "If you can read this, some things gone wrong. Bugger.";
  	int i = 0;
  	numberOfMediaItems = 10;
  	if (numberOfMediaItems < 1)
  	{
  		return "The Media library is empty";
  	  }

will it ever return "The Media library is empty";
__________________
Don't take life too seriously, it's not permanent !
xavier is offline   Reply With Quote
Old Nov 28th, 2005, 6:39 AM   #9
2roll4life7
Programmer
 
2roll4life7's Avatar
 
Join Date: Aug 2005
Location: 0x0010 * 0x0091 + 0x0004
Posts: 65
Rep Power: 4 2roll4life7 is on a distinguished road
Quote:
Originally Posted by Xenon
Sorry, im not that great with Java as you may have noticed, how to I check everything is initialized
As Xavier said, in your private array mediaItems. Have a for loop run through the entire array and at each position set the object there to whatever it should be.
__________________
#if 0 /* in case someone actually tries to compile this */
- libpng version 1.2.8 (example.c)

<Jim_McNeat> Is there like a way to put a compiler in "Just trust me on that one" mode?
2roll4life7 is offline   Reply With Quote
Old Nov 28th, 2005, 6:44 AM   #10
Xenon
Programmer
 
Join Date: Oct 2005
Location: UK
Posts: 31
Rep Power: 0 Xenon is on a distinguished road
Send a message via AIM to Xenon Send a message via MSN to Xenon Send a message via Yahoo to Xenon
Quote:
Originally Posted by xavier
I think by hand ... Also i have a question :
public String displaySound() {
  	String result = "If you can read this, some things gone wrong. Bugger.";
  	int i = 0;
  	numberOfMediaItems = 10;
  	if (numberOfMediaItems < 1)
  	{
  		return "The Media library is empty";
  	  }



will it ever return "The Media library is empty";

Oh yea the "numberOfMediaItems = 10;" was me testing stuff, ive removed it now.


Quote:
As Xavier said, in your private array mediaItems. Have a for loop run through the entire array and at each position set the object there to whatever it should be.
Sorry, I know this is really cheeky only im desperate as have absolutely no time, could you give me some code for the for loop, i know thats really cheeky.
Xenon is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:29 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC