![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
Exception in thread "main" java.lang.NullPointerExceptionJAVA Code:
Quote:
could any kind ones please tell me where have i made my mistakes? im quite pissed and sad i just cant figure it out , haih. Last edited by LuciWiz : 10-Jul-2009 at 08:51.
Reason: Please insert your Java code between [java] & [/java] tags
|
|||
|
#2
|
|||
|
|||
Re: Exception in thread "main" java.lang.NullPointerExceptionYour problem is here:
JAVA Code:
|
|
#3
|
|||
|
|||
Re: Exception in thread "main" java.lang.NullPointerExceptionYou're not giving us the whole code (classes Item and Print are missing) so we cannot test run it outselves. You're not giving us the whole sample run, so I guess one can only assume that you've chosen the first option in the menu before your sample run begins.
Generally this exception occurs when you're trying to access a non-initialized object. So it would seem that for one reason or another items[searchItem] is not initialized (since you input '2' on your test run and then subtract one, it's index 1). So it seems one must go looking to the 'choice 1' portion of the program. Here is, in my opinion, the most interesting part: JAVA Code:
If first is not 0, you do this: JAVA Code:
(As a side design note, does it really make sense that a class Item knows how many items have been entered? Does it make sense that a book in the library knows how many times the book has been borrowed?) If it returns 2, then doesn't index 1 get left unused? On the first run you insert into items[0], on the second run you insert into items[2]. That would fit together with the exception when trying to access index 1, no? This is all just speculation and guessing on my part, since I cannot test it myself. Quote:
JAVA Code:
|
|
#4
|
|||
|
|||
Re: Exception in thread "main" java.lang.NullPointerExceptionJAVA Code:
item class and btm is print JAVA Code:
|
|
#5
|
|||
|
|||
Re: Exception in thread "main" java.lang.NullPointerException... And? What were the results from mine and fakepoo's suggestions?
|
|
#6
|
|||
|
|||
Re: Exception in thread "main" java.lang.NullPointerExceptionsorry for the late reply
thanks to both of u i've finally finished up that part =D though i have a small confusing error as in below. JAVA Code:
from the menu num 5 , 6 which are public static void Transaction(){ and public static void Stock() { i've able to save the information but how do i update them into the array like how modify module does? im lost in that part , after that all my problem is solved ![]() |
|
#7
|
|||
|
|||
Re: Exception in thread "main" java.lang.NullPointerExceptionQuote:
Quote:
You already have setItemNumber etc. with which you can do this. Other than that, and I don't know much Java, you should be able to just assign another Item object into it's place. I don't know if you have to define some special member function for this to work, but I don't think so. JAVA Code:
|
Recent GIDBlog
Programming ebook direct download available by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Exception in thread "main" java.lang.NullPointerException | valley1girl | Java Forum | 12 | 18-Jun-2009 13:32 |
| Exception in thread "main" java.lang.NullPointerException | gedcraw555 | Java Forum | 3 | 25-Feb-2008 09:22 |
| Exception in thread "main" java.lang.NullPointerException | Magelloo | Java Forum | 3 | 06-May-2007 00:01 |
| Thread Stopping Exception | Gix | .NET Forum | 12 | 28-Nov-2006 05:30 |
| please help in solving: Exception in thread "main" java.lang.nullpointerexception | vkiran_v | Java Forum | 8 | 09-May-2006 08:06 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The