Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 158 Stack Exchange communities.

What is meta?
Here's how it works:
  1. Any Stack Exchange user can ask a question
  2. The community provides support, votes on ideas, and reports bugs
  3. Your voice helps shape the way Stack Exchange operates

I've run into a number of instances where I've been confused by Oracle's official documentation--mostly because I can't find the conventions they're using for their examples.

An example, while researching "contains": I'm getting a "null" error when using the statement

if(inputLine.contains("FW")) { containsFW = "FW"; }
else containsFW = "%%"; 

The Java documentation says this about the contains method: boolean contains(CharSequence s) Returns true if and only if this string contains the specified sequence of char values.

The example in the doc is nothing like code samples I've seen (and used in my code), so I'm not ever sure the right questions to ask.

What's the most appropriate way to ask "what the heck does the java documentation mean when it says X?" without suffering the public ridicule of a bunch of people commenting about how they're not here to teach java basics.

Is there an appropriate place to ask for clarification about java basics?

Is there an appropriate place to discuss how to effectvely use the java documentation to learn to ask better questions? The way the example above is written leads to more questions, not hints about what I'm doing wrong.

share|improve this question
I'm getting a "null" error when using the statement... You did initialized inputLine, did you? – Time Traveling Bobby Jul 23 '12 at 14:01
Yep...that part I figured out on my own. :) – dwwilson66 Jul 23 '12 at 15:01
up vote 7 down vote accepted

Stack Overflow is the place to ask programming questions; no matter how basic it is.

As long as you've done you research before asking the question, and make a point of that in the question, the community shouldn't ridicule you.

Be sure to include the exact error in your question.

contains() resulting in a NullReferenceException

I'm trying to use the contains() method as shown below, but I keep getting a NullReferenceException

if(inputLine.contains("FW")) { containsFW = "FW"; }
else containsFW = "%%"; 

The exact error I'm getting is:

NullReferenceException on line #blah char #blah inputLine is null or not an object

I've tried checking whether inputLine is null using the following, but I still can't work out what is wrong.

if (inputLine == null) System.out.println("Foo");
if(inputLine.contains("FW")) { containsFW = "FW"; }
else containsFW = "%%"; 

Can anyone see where I've gone wrong?

share|improve this answer
That's what I thought...SE being the place to ask anything...but got a little burned the other day when… got DOWNVOTED thrice. I felt that I'd included lots "here's what I've tried" & "here's why i tried that" research, and asked "can anyone see where I've gone wrong" instead of "fix my code". I felt it was adequate in the spirit of how I perceive SE. I've not perfected the art of question-writing just yet, but is that a reason to downvote? </vent> – dwwilson66 Jul 23 '12 at 15:09
@dwwilson66 I think you got the downvotes because you wrote lots and lots about your theories, and didn't present a simple testcase. In fact, you presented (at least) three different testcases. In the future, try to write an SSCCE - a self-contained example. In your case, that would have been only the code that actually fails. You can also provide a link to ideone, like this: , to make sure your example is reproducible. Instead of only one block of code (and a link), the question had multiple, and a lot of theories. – phihag Jul 23 '12 at 15:39
Good to know. Thanks for the clarification. Most times when I'm posting, I've got major confidentiality issues with posting the actual code and data, so I need to substitute...I think that screws me up sometimes... – dwwilson66 Jul 23 '12 at 15:42
@dwwilson66 It's not only fine to post a substitute, it is practically required. A good asker should simplify the problem down to a very simple example. In virtually all cases, you'll find the error yourself (though that shouldn't hinder you from documenting it). And simplifying the error down to the example program ensures that you haven't overlooked something. For example, I'd wager the answer to the contains question is that inputLine is null after all, and the asker hasn't seen the "Foo" output. – phihag Jul 23 '12 at 15:45
@dwwilson66: To clarify on that question you cite...the question is very basic. Everyone coding in Java should know that a return is an immediate jump out of the function, and therefor statements after those will not be executed. You should have been able to figure that out by simply reading the documentation. And that's what the downvotes are about: This question does not show any research effort; it is unclear or not useful – Time Traveling Bobby Jul 23 '12 at 16:57

What's the most appropriate way to ask "what the heck does the java documentation mean when it says X?"

That would be Stack Overflow.

...without suffering the public ridicule of a bunch of people commenting about how they're not here to teach java basics.

We are working on that. However, if you link to the documentation in your question then obviously you've found the documentation, so I don't know how much ridicule you'll get just for asking for clarification. If you get comments and answers that are not trying to help answer the question, just flag them for a moderator as "not constructive.'

share|improve this answer
Thanks, and see my comment to Matt, above. This'll at least give you a titch of context for why I'm skittish. – dwwilson66 Jul 23 '12 at 15:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .