What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 134 Stack Exchange communities.

This question already has an answer here:

I have seen so many Questions in SO and I really wanted to help these guys, but I was not able because something was missing or I could not really figure out what their problem was. So today I read the 1000th NetworkOnMainThreadException and NullPointerException question here and I decided to start this Thread.

How do I ask a android question in StackOverflow correctly:

share|improve this question

migrated from stackoverflow.com Dec 20 '13 at 18:14

This question came from our site for professional and enthusiast programmers.

marked as duplicate by Travis J, gnat, Hugo Dozois, Josh Crozier, Martijn Pieters Dec 20 '13 at 22:38

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

13  
I don't want to be "that guy" but this question should be in meta.stackoverflow :P –  pablochan Dec 20 '13 at 13:29
1  
Speaking of thread exceptions throw new ThreadOnStackOverflowException() –  weston Dec 20 '13 at 13:31
    
@pablochan So you think I should remove this, sorry do not get it –  A.S. Dec 20 '13 at 13:32
    
Not sure, this information is useful, but (ironically) the question itself does not fit the profile of this site. –  pablochan Dec 20 '13 at 13:34
    
I have nothing against NullPointerException questions as long as they are being asked in a resonable way; with good formating, nice explenation, and at least with basic understanding of the problem. –  soulreaver Dec 20 '13 at 13:35
    
I don't think questions for NetworkOnMainThreadExceptions are a problem. I've seen way more questions where I just have facepalm. –  Leandros Dec 20 '13 at 13:37
1  
As others have said, it should be on meta and it is of itself unfortunately useless. Since we don't have stickies, and you are targeting people who by and large do not attempt to help themselves first, how will they find this thread when after the first hour, it's already buried on page 3? –  Simon Dec 20 '13 at 13:55
    
You are really right guys, but I really want to help the Android people to fix their problems and I will use this thread to help them to ask it the right way. If you think I should move it just close this thread and I will delete it. –  A.S. Dec 20 '13 at 14:02
    
The intention is good and it's excellent that someone does something to improve the sad state of the Android tag. The way I see this kind of post should be done is as a community wiki "android tag FAQ" post on meta. We can then help both novices and ourselves by linking to the FAQ on meta. –  laalto Dec 20 '13 at 14:17
    
This question got closed as dup so cannot post an answer. FYI, I went ahead and edited the tag wiki stackoverflow.com/tags/android/info - adding a mention about logcat on top and links to some frequently asked questions such as NetworkOnMainThreadException. The FAQ list can be expanded with "canonical" questions that are often the target of duplicate flagging. –  laalto Dec 21 '13 at 9:30

3 Answers 3

up vote 3 down vote accepted

Thanks for reading this. Everybody of us startetd programming, but you have to research and research and read and read to get better and better. Just asking for a solution is not the best approach. Try to understand the problem and try to solve it on your own.

If you can not get rid of a crash/exception just ask us, but we need some information to help you.

  1. Post some code and try to explain what you want to do and what exactely is the problem.

  2. If you get an exception or the app crashes: Post your LogCat to the question, read the LogCat and check for your package name and post the line concerned to the exception. And then google the exception.

For Example:

12-20 14:12:05.556: E/AndroidRuntime(18957): java.lang.NullPointerException
12-20 14:12:05.556: E/AndroidRuntime(18957):    at com.example.evilmonster.lobby.LobbyScene.createScene(LobbyScene.java:52)
12-20 14:12:05.556: E/AndroidRuntime(18957):    at com.example.evilmonster.base.BaseScene.<init>(BaseScene.java:41)
12-20 14:12:05.556: E/AndroidRuntime(18957):    at com.example.evilmonster.lobby.LobbyScene.<init>(LobbyScene.java:31)
12-20 14:12:05.556: E/AndroidRuntime(18957):    at com.example.evilmonster.managaer.SceneManager$2.onTimePassed(SceneManager.java:150)
12-20 14:12:05.556: E/AndroidRuntime(18957):    at org.andengine.engine.handler.timer.TimerHandler.onUpdate(TimerHandler.java:94)
12-20 14:12:05.556: E/AndroidRuntime(18957):    at org.andengine.engine.handler.UpdateHandlerList.onUpdate(UpdateHandlerList.java:47)
12-20 14:12:05.556: E/AndroidRuntime(18957):    at org.andengine.engine.Engine.onUpdateUpdateHandlers(Engine.java:618)
12-20 14:12:05.556: E/AndroidRuntime(18957):    at org.andengine.engine.Engine.onUpdate(Engine.java:605)
12-20 14:12:05.556: E/AndroidRuntime(18957):    at org.andengine.engine.LimitedFPSEngine.onUpdate(LimitedFPSEngine.java:57)
12-20 14:12:05.556: E/AndroidRuntime(18957):    at org.andengine.engine.Engine.onTickUpdate(Engine.java:568)
12-20 14:12:05.556: E/AndroidRuntime(18957):    at org.andengine.engine.Engine$UpdateThread.run(Engine.java:858)

com.example.evilmonster.lobby.LobbyScene.createScene is my package and the Line is 52. My code is like:

private MonsterBody myBody; 
    @Override
    public void createScene() {
        myBody.getBody();       
    }

How to get the LogCat is described inside this article: http://www.vogella.com/articles/AndroidLogging/article.html

  1. Please do also some research on your own for the given exception. We have about 3 billion hits on google for NetworkOnMainThreadException and you will find a solution for it on your own.

  2. Keep in mind we do not provide a ready to deploy solution, but everybody of us is really trying to help you.

Thank you for reading! ;)

P.S. please edit this post if you think I forgot something or I did something wrong.

share|improve this answer

Just adding two small points to A.S. answer:

  • When you program doesn't do what you want, but doesn't crash

Explain what works

Example:

"I want to display an image in the top left corner but it doesn't work."

--> Does the image appear or not? If it doesn't, what to you see? If it does, where is it compared to what you expect?

I really often see some posts where there is a really nice description of what should be achieved, and some code posted, but no explanation about what the code currently does. This make it more difficult to help. In this example, knowing that the image is displayed but not at the right place is a helpful information

  • When people give you an answer or a hint that doesn't work

Try to use that hint to find some more solution or information.

Example, in your question's comment, someone wrote:

"According to your log, you have a NullPointerExeption at line 150"

--> Don't come back instantly on Stack Overflow saying "here is line 150, what should I do?". Try to solve it from the hint first

share|improve this answer

i think NetworkOnMainThreadException is arise because your work is too much load on UI thread so just use or do that particular work under AsyncTask, so you never get this error :)

share|improve this answer
    
This isn't their question. They are complaining that there are thousands of these type of question. –  weston Dec 20 '13 at 13:36

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