The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

I actually preform a null check on cur for operations that occur later.

Additional info:

n is a local variable, but was passed as a parameter. So to my knowledge as soon as I reassigned n it lost its connection to the passed array.

Post Script: I do understand your question though, because if I am being pragmatic I can concede that the system doesn't lie. So the only option here is that n is null? I guess my question for this thread is: could there be any other way I would get a null pointer there besides the fact that n is null?

Re: Null Pointer (a curious case)

Is the type for n explicitly an array, or is it just an object?

NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.

Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

The Following User Says Thank You to KevinWorkman For This Useful Post:

Re: Null Pointer (a curious case)

May I ask first, is there any other way I could get a null pointer there? Or, do you need more of the code to know for sure? In my head I keep getting this nagging urge to just stop myself and realize that an assignment cannot get a null pointer; the only way is if the array is null (). Is this not true? (assuming n is a non-primitive type)

Re: Null Pointer (a curious case)

I ask because if it is the first one (explicitly an array), you could get the length by:
n.length;
Instead of:
Array.getLength(n);

NOTE: notice no parentheses at the end of n.length. It is a variable reference, not a method call.

NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.

Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

Re: Null Pointer (a curious case)

I suggested this because if you use n.length; and still get the null pointer, it means two things:
1. the problem is independent from the Array class
2. n is null

NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.

Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

Re: Null Pointer (a curious case)

No, but perhaps that the getLength() method does something which, due to the way your array is set up or something, unexpectedly causes a null pointer to be thrown. The Array.getLength() method is a native method, so I don't have a clue what it actually does.

NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.

Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

Re: Null Pointer (a curious case)

Well that means that n is null.
n is set by the utilities.increment() method. Unfortunately, it doesn't appear that the increment() method can return null. Are you 100% sure the line you are getting the null pointer at is correct?

NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.

Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

Re: Null Pointer (a curious case)

Can you provide the full stack trace?

NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.

Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/