29

Today, I came across this question.

Title:

java lang IllegalStateException : scrollview can host only one direct child

I have relative layout in which i have table layout when i want to add the scroll view in my layout but it gives me this error.java lang IllegalStateException : scrollview can host only one direct child. here is the xml

*really long, badly formatted XML where the error is easy to see*

The error was exactly the one explained by the error message.

What should be done with questions where the exact thing to fix is actually posted in the question itself? They sure are not very constructive.

There really is no flagging reason matching these questions. These questions are a lot like the ones where you could just Google the answer; they don't show any research effort.

Should we just rely on downvoting them, or should they be flagged and with which reason?

9
  • 11
    I don't see that downvoting really helps, 99% of these questions are from new users who will never return. You should also avoid the minecraft tag if this type of question annoys you.
    – MrLore
    Jul 4, 2014 at 7:06
  • 9
    I usually downvote and put a remark pointing this paradox in OP's question. I sometime add a link to the "tour" page and/or the "How to ask" page. It is true I sometimes miss the "no research effort" close reason that doesn't exist, but the downvotes are there for this.
    – Laurent S.
    Jul 4, 2014 at 7:08
  • 5
    In cases where it's just a minor syntax error, the "Off Topic - Minor Typographical Error" close reason seems appropriate. That's what I vote when I see the common "error: semicolon missing on line 42" type questions. It doesn't fit as well in your example, though. Jul 4, 2014 at 7:33
  • go completely mad and close it as too-broad! ;)
    – user2140173
    Jul 4, 2014 at 9:34
  • 24
    Post an answer saying "A scrollview can host only one direct child." ;-) Jul 4, 2014 at 9:39
  • 4
    Curl up in a corner and cry... at least that is what I do from time to time when staying too long on SO.
    – PlasmaHH
    Jul 4, 2014 at 11:43
  • 15
    Bear in mind that someone asking a question like this may not fully understand the parent/child relationship between elements, especially if English isn't their first language. In this case specifically, it's poorly-written, but the underlying question is probably "how do I fix this, given that I'm assuming a ScrollView is for scrolling through multiple things and don't understand why there can only be one". "Just read the error" is not sufficient in this case.
    – Michelle
    Jul 4, 2014 at 12:06
  • 3
    @MrLore Wow, minecraft is a hole.
    – jonrsharpe
    Jul 4, 2014 at 13:15
  • 1
    If people read the error messages Stack Overflow would have half as many visitors.
    – Boann
    Jul 5, 2014 at 12:55

1 Answer 1

23

Personally if I got so far as spotting the problem then I'd answer it. Maybe slightly snarkily:

As the error message says, a scrollview can only hold one direct child. Your scrollview has two direct children, they are X and Y in your XML.

I would not provide a fix, even if asked for one in a comment, although if there's an obvious way to restructure then I might state it in English.

We can speculate the questioner didn't read the error message, but maybe they just don't really clock what a "direct child" is, and didn't really understand the restriction stated. If you don't really understand the jargon in front of you, it can genuinely be difficult to realise that just looking it up verbatim would explain the problem.

It's true that the question doesn't show any research effort. It should at least say for example, "I have tried to work out what 'a scrollview can only hold one direct child means', but I'm lost. What's a scrollview?". It's also a classic fit for the old "too localized" reason. So it doesn't make me sad if a question like that is closed, but when close reasons are removed I'm not going to tie myself in knots trying to find a new close reason that matches questions I didn't like for the old reason.

I think downvoting is sufficient but closing is preferred, provided that the close reason is going to make sense to the questioner, and give them some indication what they did wrong. If you wouldn't say with a straight face to a colleague who made that mistake, "there's a typo in your XML file" then it simply won't make sense to the questioner when you close for that reason and therefore won't improve their questions.

I realise that there are people who think that such bad questions shouldn't be answered, because it just encourages people to ask questions in the hope of getting help, when they should only be asking questions that contribute to the site. I occasionally help questioners even when that doesn't help the mission and I'm aware that this puts me in conflict with other users' vision for the site.

5
  • +1 for being spot on. And for harking back to old close reasons.
    – mjs
    Jul 4, 2014 at 13:47
  • @mjs: hey, I might be on to something, I haven't even been corrected yet for saying "close" :-) Jul 4, 2014 at 13:52
  • 1
    I wouldn't provide an entire fix, i.e. the entire correct XML file, but I would explain that a ScrollView should contain a single layout element like LinearLayout, and they should put the items they want to scroll through in the layout. (I would also try to improve the question...a lot.)
    – Michelle
    Jul 4, 2014 at 15:17
  • +1 for a good example of what could usefully be said as an answer, and the idea that if there isn't a good close reason for a situation, the best option is to just downvote rather than stretching out one of the other close reasons Jul 4, 2014 at 15:19
  • 3
    Personally if I got so far as spotting the problem then I'd first try to search is a canonical dupe-target exists for such type of problem, with an answer providing general explanation on how to resolve it Jul 4, 2014 at 18:43

You must log in to answer this question.

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