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 : How to use AsyncTask to execute threads in the background : How to write to the GUI from a thread : How to use Log.d : How to connect to a web service : Much more…

The code & video below will help you learn this stuff completely.

If you like videos like this, it helps to tell Google+ with a click here

You are very welcome Eventually I’ll start making games. Actually it is going to start very soon. If you understand the following parts of my Java video tutorial : 1 -7, 9, 11 – 18 and go through the Android tutorial you’ll be ready to go when I start making games. Have fun

I have been following your tutorials and I must tell you that this is one of the best Android tutorials that I have ever seen. I have learned a lot by listening your tutorials and following the same to create applications. FYI, I have not only bookmarked your site and have also forwarded your links to my friends. Are you are planning to incorporate tutorials based on Sherlock Themes and GUI design? Though, I am a beginner to Android, I am a Sr.Application Developer working on Java and othe technologies for the last 13 years. Your style of intstructions and tutoring has actually taught me to enhance my skills in Android within a shorter time frame. Looking forward to see more advanced tutorials on Android. Once again, thanks for sharing the knowledge with others who are eager to learn. Wishing you the best Derek.

Thank you for the kind message I’m very happy that you are enjoying the Android tutorials. I’m really working to make them as good as possible. Sorry they aren’t coming out faster, but my real world job has been taking all my time. ( This is just a hobby for me )

Yes I will cover themes and will show how to make much better looking apps in the future. As you can tell, I’m trying to cover as many topics as possible in each tutorial, while trying to avoid getting boring.

You’re very welcome :)Yes I didn’t go through how to catch all the errors. Sorry I made a judgement call to cover as much as possible, but not to necessarily go through extensive debugging. Here is a link to the whole package http://www.newthinktank.com/wordpress/StockQuotes.zip

One question that has been confusing me. The overall package name is “com.newthinktank.stockqutoes”, but then there’s a line in MainActivity that says “public final static String STOCK_SYMBOL = “com.example.myfirstapp.STOCK”. Why are the package names different here? It’s probably something obvious but I’d appreciate if you could tell me!

This is just a common practice in Android that is used often. You don’t have to define everything as Strings though. As the tutorial continues you’ll notice that I start passing other data types between activities. Sorry about not explaining that better

Thank you very much for these tutorials…
Your work is being extremely helpful to me.
I am following these tutorials and I have watched 8 of them, understood everything very properly.
But in the 8th one, my LogCat says “missing INTERNET permission?” and there are 24 different errors, I have done everything as you have explained, so please help me with this.

Thanks for the great tutorials. While following #8, I am having an exception as below.

java.io.EOFException
at libcore.io.Streams.readAsciiLine(Streams.java:203)
at libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:573)
at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:821)
at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:283)
at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:495)
at libcore.net.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:134)

Am I missing something here? The exception is at the time of reading the response code.

Earlier I got the missing permission issue wrt Internet which I resolved by adding

There was a bug in Android that was caused when url connections were recycled. Try updating your in Eclipse.

Also, try downloading the completed package I provide to make sure there isn’t a typo some place. Since there was no errors in your specific class files in the src folder though, but instead in the SDK I’m guessing the bug I mentioned above is causing the problem.

I have followed your tutorials and I am getting quite a few RunTime errors. First 1 being: “FATAL EXCEPTION: AsyncTask #3″
I have looked through multiple forums and tried various solutions, none of which have worked.

thanks a lot for the your videos so far, giving us the chance to learn Android development!

By the way I also struggled with the line

int responseCode = httpConnection.getResponseCode()

having had an IOException. I then added the line

to my manifest and it still fails executing the myTask.doInBackground thing..
Trying to debug I always receive the message No source code available. I am sure it somehow needs to be mapped, if so: Which code exactly and how?

Most I wonder that the logCat window does not come up with the messages which are written in the catch blocks. The one and only message which I receive is the “Before URL Creation ” in onCreate.

Actually, here’s some additional info about the problem above. When I open your app in Eclipse StockInfoActivity.java shows a lot of errors.
For example the error for line 1 is:
“Multiple markers at this line
- The type java.lang.Object cannot be resolved. It is indirectly referenced from
required .class files
- The type java.lang.String cannot be resolved. It is indirectly referenced from
required .class files”

I ‘solved’ this problem by changing project.properties file from ‘target=android-17′ to ‘target=android-19′. This enabled me to run the app in the emulator, but it crashes with the ‘FATAL ERROR’ above.

So I’m using Android Studio to do these tutorials, and trying to set up rows in the xml design tab seems pretty finicky. It usually defaults to assigning a textview with an android:layout_column. In your tutorial, you don’t use layout_column, but instead use layout_weight. It seems like layout_weight causes a lot less formatting headaches, but is layout_column supposed to be a better formatting option in TableLayouts?

I don’t think so. layout_weight is all about the total space available. So if you 1 for one component and 3 for the other they divide the total space 4 so that the second component gets 3/4ths of the space and the other gets 1/4th.

layout_column is a sort of measurement that I don’t care for because it seems to be hard to control.

Thank you Cedric, I’m happy that you are finding it useful. The reason why you are having the problem when you rotate is because I didn’t create a horizontal layout for the app. I get to how you can do that later in the tutorial. In part 19 of this series I cover it.

Click it and download the whole complete package and try running it. That will clear up any typos. Then you can compare my class files, layout files and the manifest to yours with something like diffnow.com

I finally finish this tutorial 8!!, First, I want to thank you for sharing some of your experience and knowledge with us. I have a few months trying to learn this and I have found your videos not only really informative but pedagogically sound to understand the concepts. It helps a lot your method of explaining what it does and why , while you are typing the code.

I finish this tutorial and I don’t find any red flag on my code however my emulator won’t lunch. I also copy the whole package and try to run it and I got the same response. Should I move on to tutorial 9 or focus on debugging it first?

the message I am getting is
….emulator fail to lunch.. I tried 3 different emulators.

May be my pc is the problem. Is there any labtop minimum requirements that you recommend for developing in eclipse?

After some investigation (it’s amazing how many people have this problem), I understood that there could be a problem with my home internet provider filtering somehow the “query.yahooapis.com” domain.
Switching my phone connection from home-wireless network to “mobile data”, I was able to reach “THE REST QUERY” page.

I have just finished going through all the tutorials for this project and it appeared that everything was in order. However, when I went to run the app in an emulator the app started and then instantly closed. I have tried two different emulators and the same thing happened.

I then downloaded the complete package from this webpage and set it up in Eclipse and attempted to run it. Exactly the same thing happened as before.

Sorry about the problems. I’m guessing that Yahoo changed their tags and that is the issue. Just in the past few weeks I have been getting complaints. I’ll be doing a new Android tutorials starting this month. This time I’ll try not to use anything that could possibly break.

Hi Derek,
Nice video tutorial. I had learn a lot from videos till now. Will complete the whole tutorial soon. I test the app in your tutorial on my Nexus 7 and not on the emulator as it’s very slow.

I got two errors while testing the app.
I) Once you populate the app with stocks and then you tilt the tablet(change orientation to horizontal from vertical), all list is gone and replaced by a single stock which is the last stock which you have entered(say YHOO)

II) You cannot enter a wrong symbol as it gives error after pressing the Quote button that this app have been stopped.

Can you please fix them. In the first error can you also tell how to fix the app to run only on vertical mode.

I just finished with this tutorial. I ran the program, and while it’s not catching any errors, all of the stock information returns empty when I hit the quote button. Everything else seems to be working fine, including the web button.

I’ve been going my code and comparing it to yours, but I can’t seem to find what’s wrong. Do you have any ideas as to what’s causing this?

I’ve done all the things as you have shown in this tutorial and previous but the app didn’t work. I executed the program into my android device, the app started but when i enetred the symbol of a company i.e msft and aapl and hit enter nothing happened. Plz help me solve this problem.

Hi Derek,
First of all thank u again for a wonderful tutorial!
I have a problem, after I press the ‘Quote’ button the app crashes.
Because I wrote the code manually, I compared my code with the one u provided,
and changed the ‘src’ folder and all its content to be same as your code, as well as the ‘AndroidManifest.xml’, but it still crashes!
can u please help me solve the problem?

Sorry about that. I think Yahoo randomly changes their feed. You can fix it by going in and changing based on their new feed. I’ll eliminate this issue by showing how to build your own web services very soon.