I recently answered a question and then that question was closed as duplicate of the usual canonical "null pointer exception" questions and my answer was downvoted.
As far as I am concerned, this is not useful to anyone. This was a specific case where the canonical NPE question would not have helped the person who posted the question
Since you decided to strawman the situation: no, that isn't entirely true. It also seems you only read one of the dupe targets and disregarded the other two, including the one that's directly applicable to the situation (spoiler: it's the exact same thing in a non-generic way, meaning about the exception related to the function, rather than just the exception).
You're right that not all NPE questions are automatic dupes of the canonical NPE question. That's why I hammered it as a triple duplicate, including one that isn't the NPE canonical, but that is the exact same situation that also addresses the Android-specific issue in the question.
The NPE canonical is for good measure, because not everyone understands what an NPE dupe is. I can remove that target (as well as the MyApp has stopped one) and there's still going to be a target that applies.
"Unfortunately, MyApp has stopped" is a standard hammer target for questions that don't include a stacktrace (I don't care if the error is obvious, the stacktrace is considered a fundamental part of an MCVE in the context of Android and Java crashes), as well as the canonical for findViewById()
NPEs.
I included the canonical debugging question for the same reason as I included the NPE canonical: not everyone knows how to debug apps and therefore find the relevant search keywords. "findviewbyid nullpointerexception" finds the third, non-general question on the dupe target list.
and my answer was downvoted.
I always downvote answers to bad duplicates (emphasis on bad: there are questions that're good sign posts, but this ain't one of them) I come across, assuming I still have downvotes left that day. If you have a problem with that, you can stop answering the nth dupes of questions that have already been asked so many times that at this point, people answering them do it for the rep, and not for the generation of useful content to the site. Or, you know, make sure I don't see it.
If you're looking to write a canonical answer, do so on the canonical question rather than pretending SO is a forum and posting tiny answers to several duplicates. I'm also getting back to this in a second.
I'm asking a general question about what to do when a question is closed as duplicate (using the usual canonical/general question as a reference), but I disagree with the closure.
See the above for why the question was correctly closed.
In general, the advice would be to reopen. For this question specifically, please don't. I can easily find 5 dupes of findViewById
returning null to replace every single target on that list.
If you have some new information to bring to the table, add that as a new answer to the canonical for findViewByID()
returns null (we also have a separate one for fragments and custom views that has answers that overlap with the activity one). Make the canonicals useful rather than creating a decentralized mess where some questions contain some bits of information about the exact same situation while others don't.
Serious side-note on this: Have you ever tried using a forum to find answers, where there aren't duplicate mechanics? Comments mixing with answers aside, some posts have some answers, meaning you might have to visit 5-6 threads that might not work or even apply. Forums work out even worse than Stack Overflow in terms of answer aging. While we do have a problem with answers becoming outdated, new answers can at least be added and upvoted without getting slapped by the mods for resurrecting a dead thread.
The reason SO has dupes in the first place is to minimize the number of separate "threads" (questions on SO; we aren't a forum), and also to prevent indirect answer duplication (not always the plagiarism type, but to avoid having 15 different questions that all contain the same answer of varying quality).
Your answer is essentially this one but more direct and less general, without actually explaining why findViewById
behaves that way in the first place. It's also equivalent to this one, again with the same caveats as the other one (general, no explanation of why, just "do this to fix your code") - your answer therefore adds nothing new to the overall discussion about this specific NPE, that we've already documented substantially for several different contexts. I wouldn't mind seeing these questions merged, but that's a completely unrelated discussion that doesn't affect the dupe status of the question we're discussing here.
And finally, because why not: