Android Development Tutorial 8

Get the Code Here:

Best Android Book :

Welcome to part 8 of my Android development tutorial. Today I’m going to show you how to make an android xml parser using the DOM. I’ll cover XmlPullParser next time.

I also cover numerous other topics including :
1. How to use AsyncTask to execute threads in the background
2. How to write to the GUI from a thread
3. How to use Log.d
4. How to connect to a web service
And, Much Much more…






46 responses to “Android Development Tutorial 8”

  1. Yo Gr Avatar

    If you get a ClassCastException in MainActivity.insertStockInScrollView(), just go to stock_quote_row.xml and delete the line: " android:id="@+id/stockSymbolTextView" from the TableRow. Happened to me and it solved the problem 🙂

  2. Mihai Pruteanu Avatar

    I added to my manifest file:
    <uses-permission android:name="android.permission.INTERNET"/>

    <activity android:name=".StockInfoActivity"></activity>

    And in must be written new MyAsyncTask().execute(yqlUrl); instead of new MyAsyncTask().execute();

  3. Tan Wang Avatar

    Who is passing parameters to the doInBackground() method? I am getting an exception and it looks like it's because the string array in doInBackground(String… params) is empty, so params[0] or arg[0] in your video doesn't actually exist.

    EDIT: you need to pass the yqlURL to MyAsyncTask().execute(yqlURL). He passes yqlURL as a parameter in the source code on his site but doesn't do it in the video.

  4. Yameen Yasin Avatar

    Hi Derek ! Thanks for the awesome tutorials. One small confusion ! Why do we have String parameters in angular brackets "< & >"  while creating MyAsyncTask. I have not implemented the code yet ! may get back in case I face any issues at the time of execution !

  5. Life soul Avatar

    import Thanks.showAppreciation;

    public class thankful{
    Me me = new Me.ThankYou(Good tutorials);}

  6. Jose Flores Avatar

    Great Tutorial!, A couple things for people following it:

    You have to add the permission for the app to go online, add <uses-permission android:name="android.permission.INTERNET" />  to the android manifest.

    The onPostExecute should be inside the AsyncClass you made. 

    and finally actually passing the url to the async task, new MyAsyncTask().execute(yqlUrl);

  7. John Kalogeropoulos Avatar

    Hello Derek! I have a small problem to setText after the AsyncTask has finished. Everything it seems to be ok when the AsyncTash is running(i have results in logs), but after that nothing is happening (log in onPostExecute shows nothing). Do you have any idea for resolving this? Thank you!

  8. John Kalogeropoulos Avatar

    Gongratulations Derek! Extremely very good job with all of these tutorials!

  9. Tigris Tigre Avatar

    Good job mate – you're running like crazy train sometimes, but it's good and there is always time to sit after watching and contemplate your code to embrace it fully 😉

  10. Mohammad Tsalis Avatar

    I got the app up and running, but it gets error only when I try to get quote from the quoteStockButton, the quoteFromWebButton works perfectly

    On my logcat I got AndroidRunTime error saying "unable to find activity class {com.newthinkthank.stockquote/com.newthinkthank.stockquote.StockInfoActivity}, have you declared this activity in your AndroidManifest.xml?"

    What does it mean by have you declared in AndroidManifest.xml?
    does it mean I have to manually add my src to AndroidManifest?

  11. 60gapple Avatar

    big fan of these tutorials. Im getting a fatal error with this program though. I've replaced my typed-in code with that available on the link and I still get the same error:
    java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
                at com.example.nicolasroux.stockquote.MainActivity.insertStockInScrollView(
                at com.example.nicolasroux.stockquote.MainActivity.updateSavedStockList(
                at com.example.nicolasroux.stockquote.MainActivity.saveStockSymbol(
                at com.example.nicolasroux.stockquote.MainActivity.access$100(
                at com.example.nicolasroux.stockquote.MainActivity$1.onClick(
                at android.view.View.performClick(
                at android.view.View$
                at android.os.Handler.handleCallback(
                at android.os.Handler.dispatchMessage(
                at android.os.Looper.loop(
                at java.lang.reflect.Method.invoke(Native Method)
                at java.lang.reflect.Method.invoke(

    Please help.

  12. Burak Karasoy Avatar

    Hi.My web button works correct but when ı click quote button,I got error W/EGL_emulation﹕ eglSurfaceAttrib not implemented on my log cat.
    and I have an empty activity_stock_info there is no information about companies

  13. Piyush Agarwal Avatar

    onPostExecute method is not called is that method working??

  14. alzhn Avatar

    If you are crashing when you hit "QUOTE", if your logcat shows that it fails with a runtime exception similar to this 
    " E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #1 "
    then make sure you allow your app to get permission for accessing the internet by adding the following line to the manifest file.
    <uses-permission android:name="android.permission.INTERNET" />

    Also, as +thuckz pointed out in a comment below, make sure that you add "yqlURL" inside of "new MyAsyncTask().execute()" so that it now looks like this "new MyAsyncTask().execute(yqlURL) "

  15. Idan Biton Avatar

    hey derek and thanks a lot for this amazing tutorial! 
    I have a little problem when i'm executing the app and the emulator is on when i try to start the app i get a message "unfortunately, stockQuote has stopped.
    what could be the problem? thanks 🙂

  16. RodRigo Garcia Avatar

    Hi Derek! Congratulations for you tutorial, is really really making a difference for me in this quest in learning Android and Java at the same time.. hehe. Although I'm wondering how to implement some parts of this code to parse an XML file that is on the computer (or in the phone) and not on the Web, which method, classes and variables are and are not needed?. And also if I need to use a Try-Catch method even if I'm not extracting nothing from the Web. Thank you very much in advance!!

  17. Djordje Jokic Avatar

    I copied the code from the website, but when trying to insert data into the scrollView I get an error:

    android.widget.TableRow cannot be cast to android.widget.TextView
    MainActivity.insertStockInScrollView( which is:
    TextView newStockTextView = (TextView) newStockRow.findViewById(;

    Did anyone else have the same problem? I'm using Android Studio though (don't know if that has anything to do with it). 

  18. Pradeep Basavaraj Avatar

    getResponseCode() is throwing exception
    Could you please help?

  19. billdavidson6 Avatar

    The code given on the web site in the zip file is broken.

    activity_stock_info doesn't have enough TextView's.  The code in works around this by using hard coding of strings to do the labels which is supposed to be a no-no in Android.

  20. joeydb1 Avatar

    Excellent tutorials Derek.  I would like to make a request for a future tutorial that will show a dual use case – where a single base of code can be used both as an android app and as a Java application that will run on Windows.  I understand that it would be necessary to launch each of these modes differently.  In any case, keep up the great work.  I have seldom learned so much in such a short amount of time as your format allows.

  21. Mark Keen Avatar

    +Derek Banas 

    Fantastic tutorial!  I have the 'web' function working as desired, but I get a force close when I hit the quote button (using DOM method);

    10-13 10:51:35.836  13155-13241/com.home.markkeen.stockquote E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #3
        Process: com.home.markkeen.stockquote, PID: 13155
        java.lang.RuntimeException: An error occured while executing doInBackground()
                at android.os.AsyncTask$3.done(
                at java.util.concurrent.FutureTask.finishCompletion(
                at java.util.concurrent.FutureTask.setException(
                at android.os.AsyncTask$SerialExecutor$
                at java.util.concurrent.ThreadPoolExecutor.runWorker(
                at java.util.concurrent.ThreadPoolExecutor$
         Caused by: java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
                at com.home.markkeen.stockquote.StockInfoActivity$MyAsyncTask.doInBackground(
                at com.home.markkeen.stockquote.StockInfoActivity$MyAsyncTask.doInBackground(
                at android.os.AsyncTask$
                at android.os.AsyncTask$SerialExecutor$
                at java.util.concurrent.ThreadPoolExecutor.runWorker(
                at java.util.concurrent.ThreadPoolExecutor$

    Any Ideas? I have tried checking the code, but to be honest some of it (most ) is a bit beyond my current skill level.

    Many thanks.

  22. Thair Jaber Avatar

    +Derek Banas  sorry ,but when i click on Quote Button the app stops i tried to solve it but ' dont know what it could be ..
    and this is LogCat .. and Thanx For Help

    10-09 16:29:34.270: E/AndroidRuntime(31507): FATAL EXCEPTION: main
    10-09 16:29:34.270: E/AndroidRuntime(31507): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.stockquote/com.example.stockquote.StockInfoActivity}; have you declared this activity in your AndroidManifest.xml?
    10-09 16:29:34.270: E/AndroidRuntime(31507): at
    10-09 16:29:34.270: E/AndroidRuntime(31507): at
    10-09 16:29:34.270: E/AndroidRuntime(31507): at
    10-09 16:29:34.270: E/AndroidRuntime(31507): at
    10-09 16:29:34.270: E/AndroidRuntime(31507): at
    10-09 16:29:34.270: E/AndroidRuntime(31507): at
    10-09 16:29:34.270: E/AndroidRuntime(31507): at
    10-09 16:29:34.270: E/AndroidRuntime(31507): at com.example.stockquote.MainActivity$3.onClick(
    10-09 16:29:34.270: E/AndroidRuntime(31507): at android.view.View.performClick(
    10-09 16:29:34.270: E/AndroidRuntime(31507): at android.view.View$
    10-09 16:29:34.270: E/AndroidRuntime(31507): at android.os.Handler.handleCallback(
    10-09 16:29:34.270: E/AndroidRuntime(31507): at android.os.Handler.dispatchMessage(
    10-09 16:29:34.270: E/AndroidRuntime(31507): at android.os.Looper.loop(
    10-09 16:29:34.270: E/AndroidRuntime(31507): at
    10-09 16:29:34.270: E/AndroidRuntime(31507): at java.lang.reflect.Method.invokeNative(Native Method)
    10-09 16:29:34.270: E/AndroidRuntime(31507): at java.lang.reflect.Method.invoke(
    10-09 16:29:34.270: E/AndroidRuntime(31507): at$
    10-09 16:29:34.270: E/AndroidRuntime(31507): at
    10-09 16:29:34.270: E/AndroidRuntime(31507): at dalvik.system.NativeStart.main(Native Method)

  23. Chris Summers Avatar

    Hi Derek,
       Do you have  to remove super.onPostExecute(result)? I wanted to keep that just in case the super class provided behavior in that method i needed.

  24. Chris Summers Avatar

    Hi Derek,
         Does getElementsByTagName only work with direct descendents or all descendents? I saw that quote isn't a direct descendent of the root element. So is it ok to just call that method and get all descendents?

  25. Chris Summers Avatar

    Hi Derek,
        This is kinda of a unrelated question but i saw that on yql console, there was a community table for quotes and stocks. Is there a difference between the two?

  26. mt5070 Avatar

    there is a problem running mine app 
    unfortunately project_name has stopped

  27. broccollin Avatar

    I've been trying to learn how to make Android apps for a job I'm trying to get and this has been massively helpful, thank you. Much better than the Google guide

  28. pedro gutierrez Avatar

    dear Coaching, in what chapter are you are taching us "How to install the app in the real Table?, Sorry for the question!!! .. im from venezuela willing to learn

  29. Cheukman Chiu Avatar

    Hi , Derek , l have just watched through the Android Development tutorial 8 , but for line 274 in the , l dun know why the complier said this is a bug for "" , for the stock_info , There are 3 quick fixes available    1.Create field "stock info" in type menu  2. Create constant stock info in type menu  3. change to "main"            
    Which fix should l choose or do l need to do other stuffs in order to solve the problem? Thanks Derek !

  30. C Williams Avatar

    So everything works fine but when i run it in the emulator and then press quote it crashes the whole entire app. What do i need to do about that

  31. Alfons Schuhbeck Avatar

    Is the strings.xml URL-Error still there in Android Studio 0.8.2?

  32. Bill Broughton Avatar

    Yes, it's me again.  Everything seems to be working right up until I call "startActivity ( either getStockFromWebsiteListener or getStockActivityListener) The device displays "Unfortunately, StockQuote has stopped."  I have double checked the code several times.  What am I missing?

  33. Aishwary Tandon Avatar

    hi derek ! thanks a lot for providing such an awesome series.I just want your suggestion on what's the best way to  grasp the different concepts from your videos. Should i just listen to your tutorial all at once and then copy paste the code or shud I just pause video after each and every step. What approach would you take if you are learning a new language from scratch?

  34. Kidus Tiliksew Avatar

    Derek, do you have any tutorials on how to make games for Android? I feel like that's the sort of the thing I want to do

  35. Daniel Almeida Avatar

    Hi Derek, hooray from Brasil! 🙂

    I'm new to programming in general, and after running your app I get a IndexOutOfBoundsException when anything other than 0 is passed into addView(newStockRow, arrayIndex)…(addView(newStockRow, 0) works fine). What does this index represent? Also, String isTheStockNew will always be set with what the user has typed, even if it's a new stock it won't be "null".

    Lastly, if I was to rewrite the String stocks[] part using collections, what would I do? just point me to the right way and i'll research the specifics.

    These tutorials are great, thanks for the help! 

  36. Mark Irving Avatar

    Excellent tutorial. Thank you

  37. Ido Savir Avatar

    thanks for a great tutorial. i downloaded the code and tried to run it but for some reason it throws an IO exception. i didnt change anything just ran the code downloaded. the exception is -> Unable to resolve host "": No address associated with hostname
    I tried to put the url used in the browser and it seems fine. what could be wrong?

  38. Chris Summers Avatar

    Hi Derek,
       Would going on the webpage be an implicit intent as youre another feature of the android os, browser?

  39. Chris Summers Avatar

    Hi Derek, if onPostExecute waits for doibackground to complete, doesnt that beat the whole purpose of using threads? User's screen will be locked until the xml request is complete? Can you explain this?

  40. Chris Summers Avatar

    Hi Derek,
        Is onPostExecute running on its own thread as well or is it executing on the ui thread?

  41. Chris Summers Avatar

    Hi derek, 
        When was the url passed into myasynctask? I just noticed that the url was constructed with the different components but you never passed it into myasynctask

  42. Chris Summers Avatar

    Hi Derek,
         How do you get the spacing between the rows done? I tried looking over your code but didnt find anything that dealt with this

  43. alexsc1309 Avatar

    I am using Android Studio instead of Eclipse and I prefer not to just import your project but really type everything you do in manually ( hoping to increase the learn curve that way ).

    In this project now I have one problem in and even when I copy paste the full code for the file from your site it still persists.

    getMenuInflater().inflate(, menu);  It says cannot resolve symbol stock_info . I checked your full source code posted on your web link and there seems to be no symbol by that name defined. Can you maybe tell me how to fix it? Thanks.

  44. Sugam Mankad Avatar

    Awesome Tutorials Derek, but I am getting an error "threadid = 1: thread exiting with uncaught exception (group=0x40c93258) in orange color, and then in next lines it says Android Runtime Error in red. Please Help…. 
    Tag dalvikvm
    And I Found Out that yqlURL is unused ….

  45. Jeffrey Paula Avatar

    Did I miss a step on creating the stockInfoActivity? I don't have that, and I don't have those java sources. I only have main So I am a little confused.

  46. Coast Avatar

    Firstly, thank you so much for these tutorials. In your opinion, Derek, do you think I should be trying to create the app as you go along, or do you think watching the whole video and copying the code at the end will be enough for me to get comfortable if I keep watching the videos? I'm trying really hard to understand the logic of what's going on to eventually apply it to my own app building but there are still so many terms that I'm not really comfortable with yet, sometimes I'm completely lost.

Leave a Reply

Your email address will not be published. Required fields are marked *