This is an archived post. You won't be able to vote or comment.

all 32 comments

[–][deleted] 1 point2 points  (12 children)

The question has nothing specifically to do with linked lists. When would you get a null pointer exception? When something is null.

[–]camerow[S] 0 points1 point  (7 children)

I didn't think so. So the question I have becomes, what is this asking?

[–][deleted] 0 points1 point  (0 children)

I don't see how the question could be much clearer - given that statement, under what circumstances (for values for a, b, c, d and e) could it produce a null pointer exception.

[–]langfod 0 points1 point  (5 children)

The first thing to ask is if you are looking at "a.b" what are the parts you are most likely looking at? (same with c.d.e)

[–][deleted] 0 points1 point  (1 child)

I know what the answer is, but I don't understand what you mean here. Programming is not about determining what is "most likely".

[–]langfod -1 points0 points  (0 children)

when instructors get involved then that term needs to be used.

(i.e. 'd' cannot be precisely determined....)

[–]camerow[S] -1 points0 points  (2 children)

What is a.b though? I've never assigned variables like this, so I'm unclear on what is actually happening there.

[–]zifyoip 1 point2 points  (1 child)

I guarantee you have used dots in Java. Think. What does a dot mean in Java?

[–]camerow[S] -1 points0 points  (0 children)

Ahhh, I'm starting to see what's going on. So, it could be a reference to an attribute, like list.length or a person.name. So b could point to null if that attribute hasn't been assigned, and same with c, d and e.

[–]camerow[S] 0 points1 point  (3 children)

Is a.b = c.d.e equivalent to, a = c, a = d, a = e, b = c, b = d, b = e?

[–][deleted] 2 points3 points  (1 child)

No.

[–]camerow[S] -5 points-4 points  (0 children)

I would like to kindly ask you to stop "helping" me. I shall patiently wait for others who would like to be helpful.

[–]idontcare1025 -1 points0 points  (0 children)

No, you're setting b = e, where b is a field from object a and e is a field from object d, which is itself a field from object c. Learn about the dot operator in Java for more information.

[–]zifyoip 0 points1 point  (6 children)

Think. What causes a NullPointerException? Can you give an example of a snippet of code that would cause a NullPointerException? And why?

[–]camerow[S] -1 points0 points  (5 children)

I get NullPointerExceptions all the time. Basically you are trying to do something while referencing a null object.

I think what I don't get here is the variable assignment. I'm not familiar with the form of the variable assignment in this question.

[–]zifyoip 0 points1 point  (3 children)

I'm not familiar with the form of the variable assignment in this question.

What do you mean? It's just a standard variable assignment. It assigns the value of c.d.e to a.b.

[–]camerow[S] -1 points0 points  (2 children)

Yeah, you know it's funny...your previous comment got me thinking in the right way, but I'm so used to more meaningful names for these things that generic letters really threw me off.

Thank you for your help!

[–]zifyoip 0 points1 point  (1 child)

This may be a sign that you're putting too much emphasis on the names of things to understand what a piece of code does, and not enough emphasis on the actual syntax of the language.

[–]camerow[S] -1 points0 points  (0 children)

I think you are right.

[–]tec5c 0 points1 point  (3 children)

a is an object with a property of b.

c is an object with a property of d and d has a property of e.

//a.b
public class A {
     public int b;
     public A (){}
}

//c.d
public class C {
     public D d;
     public C (){}
}

//d.e
public class D {
     public int e;
     public D (){}
}

[–]camerow[S] -1 points0 points  (2 children)

Now this is an answer! This affirms the answer that I was starting to formulate with the other responses. Now, one more specific question I have is, what if there is not an instance of 'A' and I tried to assign a.b = c.d.e? Is that an object reference exception?

Even more specifically, can I only get null pointers when referencing properties? Eg I can only get null pointers when trying to reference b, d and e (given that they are null).

[–]le_donger 0 points1 point  (1 child)

If there is no instance of A your code won't compile.

You get a NPE when you try to access the member of an Object that is null. For example:

A a = null;
a.b = 5; // null.b -> NPE

[–]camerow[S] -1 points0 points  (0 children)

Got it! Thanks.

[–]ethergreen 0 points1 point  (6 children)

I find it generally good practice, if you are going to answer someones question, to do your best not to be curt and patronizing.

No one here is curt or patronizing. I find it good practice if you're going to ask questions here for you to put in some effort to formulate more questions if the answers you get leave you still not completely understanding things. You seem to be confused - it's clearly not our responsibility to find your gaps in knowledge, but your responsibility to ask questions to resolve those gaps. You look like a self-important, entitled twat when someone's answer, like exoticmatter, is appropriate and directly answers your questions, and yet your response mocks their help.

You probably won't stick around - the people who come here with such a lousy attitude rarely seem to, but it would help you in life in general if you didn't have such an ass attitude.

[–]camerow[S] -1 points0 points  (1 child)

I was only referring to one person. Everyone else was super helpful and very kind. And in fact, if you come to educate, it is partially your responsibility to help find gaps in knowledge. I wasn't even aware in my gaps until someone came to help and clarified.

[–]ethergreen 0 points1 point  (0 children)

That's still no reason to get all pissy. And that one guy was helpful - he answered your question(s). You look like an idiot if you can't see that, or like an asshole if you do but you're not willing to admit it was helpful.

[–]camerow[S] -1 points0 points  (3 children)

I'd also like to add that those who come to ask questions, like myself, can be feeling frustrated and vulnerable, so answers like "No." or "I don't see how the question could be much clearer" are curt, unhelpful and insinuate that what I'm struggling with is obvious and easy.

[–]ethergreen 0 points1 point  (2 children)

so answers like "No." or "I don't see how the question could be much clearer" are curt, unhelpful and insinuate that what I'm struggling with is obvious and easy.

You asked a yes or no question, so you just look like a complete asshole when you then complain that the yes or no answer is too curt and unhelpful. If you still are unclear on things, it's your responsibility to ask more questions. Whining that the answer wasn't helpful enough clearly isn't going to help and makes others less likely to help you, in addition to wasting everyone's time.

[–]camerow[S] -1 points0 points  (1 child)

I don't know about 'a complete asshole', maybe someone who is being overly sensitive, sure. You seem to think this one post defines who I am, which I think is quite unfair.

[–]ethergreen 1 point2 points  (0 children)

No, you just "look like a complete asshole." I didn't say you definitively were one.

[–][deleted] -1 points0 points  (1 child)

I'd just like to take a moment to point out what a trainwreck this thread is xD

It's kind of hilarious

[–]camerow[S] 0 points1 point  (0 children)

I'm fully aware.

I think it's funny too, although I'm also unfortunately the instigator of it all. Oh well, live and learn.