Please copy and paste the full text of the error message.
If you know what line the variable with the null value is on, look at that line, find the variable with the null value and then backtrack in the code to see why that variable does not have a valid value.

February 4th, 2013, 10:23 AM

xJavaLover

Re: Need some help getting this code to run...

Code :

for(Packet mypacket : shipment)

It says, java.lang.NullPointerException
at Packages.toString(Packages.java:78)
at java.lang.String.valueOf(String.java:2854)
at java.io.PrintStream.println(PrintStream.java:821)
at TestPackages.main(TestPackages.java:10)

February 4th, 2013, 10:27 AM

Norm

Re: Need some help getting this code to run...

Try debugging the code by adding some println() statements that print out the value of the shipment variable every time its value is changed and set to see why it has a null value.

February 4th, 2013, 10:40 AM

xJavaLover

Re: Need some help getting this code to run...

what will I be printing in...string s, int id, double d? in the array loop?

February 4th, 2013, 11:10 AM

Norm

Re: Need some help getting this code to run...

Just print the value of the shipment variable every time it is changed:
System.out.println("s1="+shipment);
change the digit to be unique in each call to println() so you can tell which println() printed the output.

February 4th, 2013, 11:57 AM

xJavaLover

Re: Need some help getting this code to run...

I got the code to compile and run but it only outputs "ALL PACKETS" text...I don't know what's going on.

Try debugging the code by adding println() statements that print out the value of shipment at all locations in the code where the value of the variable: shipment is changed. You need to see if and when the value of and contents of shipment changes.
See post#6

but whyyyy I read the file in right...I believe. I don't know if my array is set-up right.

February 4th, 2013, 01:16 PM

Norm

Re: Need some help getting this code to run...

What was printed out when you added all the println() calls I suggested to the code?
You need to add lots of println() statements to see what the code is doing.
The code you posted looks like it added just one println and that is NOT what I was suggesting as a place to add any.

February 4th, 2013, 09:26 PM

xJavaLover

Re: Need some help getting this code to run...

Quote:

Originally Posted by Norm

What was printed out when you added all the println() calls I suggested to the code?
You need to add lots of println() statements to see what the code is doing.
The code you posted looks like it added just one println and that is NOT what I was suggesting as a place to add any.

OK I figured it out...my array now prints the input file.

BUT my methods (displayHeavyWeight, displayLightWeight...etc) are not being displayed or called I believe...how do I go about implementing that? When I run the output my strings do not show up...