Creating A Simple RSS Application in Android
In this tutorial we will build a simple rss application.
Requirements are:
1) parse an rss feed and display the headlines in a ListView
2) when the user clicks on a headline, open the Android browser and redirect to corresponding web page.
We will parse the PCWorld‘s rss looking for the latest news: http://feeds.pcworld.com/pcworld/latestnews
The final result will look like in the screenshot below:
1. Create a new project in Eclipse:
Project: SimpleRssReader
Activity: SimpleRssReaderActivity
2. Add required permissions to AndroidManifest file.
The application will make use of Internet, so this should be specified in the AndroidManifest file, otherwise an exception will be thrown. Just after the <application> tag, (as a child of <manifest> tag), add the following line:
<uses-permission android:name="android.permission.INTERNET"/>
3. Open the main.xml layout file, delete the already existing TextView control, and add instead a ListView with the id “list”. This should should look like this:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ListView android:id="@+android:id/list" android:layout_width="fill_parent" android:layout_height="wrap_content" > </ListView> </LinearLayout>
4. Lets create the skeleton of our main activity.
Open the SimpleRSSReaderActivity and make it extend ListActivity, instead of Activity as it comes by default. We need this in order to display the headlines in the ListView by binding to an array which will hold our data, using the list view adapter.
Add 2 instance variables: “headlines” and “links” of type List.
It should look like this:
public class SimpleRSSReaderActivity extends ListActivity {
List headlines;
List links;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
5. In the onCreate() method, just after the setContentView(….) , add following lines:
// Initializing instance variables
headlines = new ArrayList();
links = new ArrayList();
try {
URL url = new URL("http://feeds.pcworld.com/pcworld/latestnews");
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(false);
XmlPullParser xpp = factory.newPullParser();
// We will get the XML from an input stream
xpp.setInput(getInputStream(url), "UTF_8");
/* We will parse the XML content looking for the "<title>" tag which appears inside the "<item>" tag.
* However, we should take in consideration that the rss feed name also is enclosed in a "<title>" tag.
* As we know, every feed begins with these lines: "<channel><title>Feed_Name</title>...."
* so we should skip the "<title>" tag which is a child of "<channel>" tag,
* and take in consideration only "<title>" tag which is a child of "<item>"
*
* In order to achieve this, we will make use of a boolean variable.
*/
boolean insideItem = false;
// Returns the type of current event: START_TAG, END_TAG, etc..
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
if (xpp.getName().equalsIgnoreCase("item")) {
insideItem = true;
} else if (xpp.getName().equalsIgnoreCase("title")) {
if (insideItem)
headlines.add(xpp.nextText()); //extract the headline
} else if (xpp.getName().equalsIgnoreCase("link")) {
if (insideItem)
links.add(xpp.nextText()); //extract the link of article
}
}else if(eventType==XmlPullParser.END_TAG && xpp.getName().equalsIgnoreCase("item")){
insideItem=false;
}
eventType = xpp.next(); //move to next element
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// Binding data
ArrayAdapter adapter = new ArrayAdapter(this,
android.R.layout.simple_list_item_1, headlines);
setListAdapter(adapter);
6. In the onCreate() method we passed an input stream to setInput(): xpp.setInput(getInputStream(url), "UTF_8");
getInputStream() is not a standard Java method, so we should create it. This method should take as an argument the feed url, and return the input stream.
public InputStream getInputStream(URL url) {
try {
return url.openConnection().getInputStream();
} catch (IOException e) {
return null;
}
}
7. Finnaly, we want when a title is clicked, the Android browser to be opened and display the corresponding article. This one is simple, we override the onListItemClick() method, get the position of article in the ListView, retrieve the coresponding link, and pass the url of that article to ACTION_VIEW intent which takes care further of displaying the web page.
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Uri uri = Uri.parse(links.get(position));
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
By this time you should compile and run successfully the application.
Well, if everything went fine and you are done with the simple rss application, the next step to consider is how can you enhance the visual aspect of the application. Adding some style to the ListView, for example alternating between background colors, or displaying an icon next to each headline, can considerably increase the visual aspect, which will make your application look more appealing.
Take a look at this tutorial: Building a Custom Fancy ListView in Android, where I show in details how to achieve this.
This application, however, has one major drawback. Its drawback is that all the parsing and network access is done on the UI thread. As a result, you may notice that when starting the application, it “freezes” for a few seconds and then displays the headlines. To fix this issue, you should put all the parsing functionality in a background thread. In regards how to do that, you definitely should consider this post: Understanding AsyncTask – Once and Forever





Really helpful blog….Thank you…….
I am following your guide but I have some problems..
============================================================
ERROR 1:
if (xpp.getName().equalsIgnoreCase(“item”)) {
insideItem = true;
} else if (xpp.getName().equalsIgnoreCase(“title”)) {
if (insideItem)
headlines.add(xpp.nextText()); //extract the headline
} else if (xpp.getName().equalsIgnoreCase(“link”)) {
if (insideItem)
links.add(xpp.nextText()); //extract the link of article
}
Error:
links.add & headlines.add – The method add(R.string) in the type List is not applicable for the arguments (String)
============================================================
ERROR 2:
// Binding data
ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, headlines);
setListAdapter(adapter);
Error:
The constructor ArrayAdapter(SimpleRssReaderActivity, int, List) is undefined
=============================================================
ERROR 3:
protected void onListItemClick(ListView l, View v, int position, long id) {
Uri uri = Uri.parse(links.get(position));
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
Error:
Uri.parse – The method parse(String) in the type Uri is not applicable for the arguments (R.string)
How do I fix this?
Hi,
I believe the errors that appear in the program are caused by the improper use of quotes.
It could be that you copied the source code, or the computer language is not english, and an improper encoding was generated when
you put them.
To fix this, manualy change in all equalsIgnoreCase() methods the quotes, from “ ” to ” “.
(If needed change the computer language to EN – English)
This should fix as well the ERROR 2, and ERROR 3.
Later Edit: I see the wordpress does not format the quotes ” ” as they should look. They should look straight, not inclided.
i have tried replacing the quotes manually but the issue remain unresolved..
plz help..
plz reply ASAP…
i have no idea if you still look at this thread, but, i have the same error in this line:
Uri uri = Uri.parse(links.get(position));
error:
The method parse(String) in the type Uri is not applicable for the arguments (Object) MainActivity.java/RSS-Reader/src/com/rss_reader
if i just cast it like this:
Uri uri = Uri.parse((String) links.get(position));
app is running, till i try to open an item.
after that the app stopps ….
any idea why?
For problem with Uri: change ArrayList headlinks = new ArrayList(); to ArrayList = new ArrayList; and with links do same.
very helpful tutorial, but i have some problem with this program, the problem is if there’s no internet connection, the program will have an error and you need to force close it, my question is, how can i program that if there’s no internet connection a dialog box will pop up and says “No internet connection” and it will go back to my Menu. can you please tell me how should i do? thanks a lot
Hi,
I updated one of my previous posts where I was talking about how to detect the internet connection, to include the use of AlertDialogs when there’s no internet connection.
Take a look here:
http://androidresearch.wordpress.com/2012/01/06/android-detecting-internet-connection.
Thanks a lot 4 tips
can we display headlines and description in a single text box .head lines in bold style and description in normal mode.
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
if (xpp.getName().equalsIgnoreCase(“item”)) {
insideItem = true;
} else if (xpp.getName().equalsIgnoreCase(“title”)) {
if (insideItem)
headlines.add(xpp.nextText()); //extract the headline
}else if (xpp.getName().equalsIgnoreCase(“description”)) {
if (insideItem)
headlines.add(xpp.nextText()); //extract the headline
} else if (xpp.getName().equalsIgnoreCase(“link”)) {
if (insideItem)
links.add(xpp.nextText()); //extract the link of article
———–
headlines.add(xpp.nextText()); //extract the headline
headlines.add(xpp.nextText()); //extract the description
please help…. ?
You will need to create a new List that will store descriptions, just like we store headlines and links.
To make the headline and description appear in the same text box, most probably you will need to define a new layout file and then bind this layout file to your ListView. Take a look at this tutorial: Building a Custom Fancy ListView in Android
To make a text bold, add this property to the corresponding TextView:
android:textStyle=”bold”
nice tutorial as always !!
but how to grap info from xml of this type?
sry i cant post xml code… heres a screen shot
http://s13.postimage.org/4qpzy2enr/Untitled.png
Thanks!
I do not understand what you meant. Please explain it, give some more information.
i replied with a picture couse the xml code i posted doesnt show.
The xml code does not contain a start/end tag , its embedded in one line
http://s13.postimage.org/4qpzy2enr/Untitled.png
That is a document with a self-closing tag,
and I suppose in this case you need to read the attributes of those tags, for example DBID, EID, and so on. Personally I did not work with files like this yet, but I saw that XMLPullParse has specific methods to work with, like: getAttributeCount();, getAttributeName(), and getAttributeValue().
However, the topic is interesting, and I’m going to explore it, and eventually writing a post.
ok thanks for the help! gone dig up more about those methods to grap the properties
cheers!
When I run I get this :
04-04 20:13:36.402: E/AndroidRuntime(580): FATAL EXCEPTION: main
04-04 20:13:36.402: E/AndroidRuntime(580): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mkyong.android/com.mkyong.android.SimpleRSSReaderActivity}: android.os.NetworkOnMainThreadException
04-04 20:13:36.402: E/AndroidRuntime(580): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
04-04 20:13:36.402: E/AndroidRuntime(580): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
04-04 20:13:36.402: E/AndroidRuntime(580): at android.app.ActivityThread.access$600(ActivityThread.java:123)
04-04 20:13:36.402: E/AndroidRuntime(580): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
04-04 20:13:36.402: E/AndroidRuntime(580): at android.os.Handler.dispatchMessage(Handler.java:99)
04-04 20:13:36.402: E/AndroidRuntime(580): at android.os.Looper.loop(Looper.java:137)
04-04 20:13:36.402: E/AndroidRuntime(580): at android.app.ActivityThread.main(ActivityThread.java:4424)
04-04 20:13:36.402: E/AndroidRuntime(580): at java.lang.reflect.Method.invokeNative(Native Method)
04-04 20:13:36.402: E/AndroidRuntime(580): at java.lang.reflect.Method.invoke(Method.java:511)
04-04 20:13:36.402: E/AndroidRuntime(580): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-04 20:13:36.402: E/AndroidRuntime(580): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-04 20:13:36.402: E/AndroidRuntime(580): at dalvik.system.NativeStart.main(Native Method)
04-04 20:13:36.402: E/AndroidRuntime(580): Caused by: android.os.NetworkOnMainThreadException
04-04 20:13:36.402: E/AndroidRuntime(580): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
04-04 20:13:36.402: E/AndroidRuntime(580): at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
04-04 20:13:36.402: E/AndroidRuntime(580): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
04-04 20:13:36.402: E/AndroidRuntime(580): at java.net.InetAddress.getAllByName(InetAddress.java:220)
04-04 20:13:36.402: E/AndroidRuntime(580): at libcore.net.http.HttpConnection.(HttpConnection.java:71)
04-04 20:13:36.402: E/AndroidRuntime(580): at libcore.net.http.HttpConnection.(HttpConnection.java:50)
04-04 20:13:36.402: E/AndroidRuntime(580): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351)
04-04 20:13:36.402: E/AndroidRuntime(580): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)
04-04 20:13:36.402: E/AndroidRuntime(580): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
04-04 20:13:36.402: E/AndroidRuntime(580): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)
04-04 20:13:36.402: E/AndroidRuntime(580): at libcore.net.http.HttpEngine.connect(HttpEngine.java:303)
04-04 20:13:36.402: E/AndroidRuntime(580): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
04-04 20:13:36.402: E/AndroidRuntime(580): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
04-04 20:13:36.402: E/AndroidRuntime(580): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273)
04-04 20:13:36.402: E/AndroidRuntime(580): at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:168)
04-04 20:13:36.402: E/AndroidRuntime(580): at com.mkyong.android.SimpleRSSReaderActivity.getInputStream(SimpleRSSReaderActivity.java:92)
04-04 20:13:36.402: E/AndroidRuntime(580): at com.mkyong.android.SimpleRSSReaderActivity.onCreate(SimpleRSSReaderActivity.java:42)
04-04 20:13:36.402: E/AndroidRuntime(580): at android.app.Activity.performCreate(Activity.java:4465)
04-04 20:13:36.402: E/AndroidRuntime(580): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-04 20:13:36.402: E/AndroidRuntime(580): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
04-04 20:13:36.402: E/AndroidRuntime(580): … 11 more
It’s because you are not allowed to perform network operations on the UI thread. This seems to be a feature introduced in the latests SDK versions. I created the application in Android 2.2
To solve this problem you should perform the RSS download in a separate thread, AsyncTask can help with this.
In this post: http://androidresearch.wordpress.com/2012/03/17/understanding-asynctask-once-and-forever/, I explain how to solve this problem.
Hi there,
Thanks for the great tutorials. A guide on making a simple rss reader is exactly what I’ve been looking for! I’ve got a couple of issues though:
I implemented the AsyncTask code from your other guide on this project since I’m writing for the latest version of the SDK which requires you to put all network operations like this. When I run the project it doesn’t seem to show anything. I’m not sure if the information isn’t being downloaded, or it’s not binding to the list items correctly, any ideas?
Also eclipse is complaining about using the raw type versions of List and ArrayAdapter. Should these be List and ArrayAdapter for generic types?
Thanks!
Actually I went through debugging, and the rss feed headlines are definitely being stored in the headline list, just not displaying.
Never mind! I figured it out. The method call to populate the header using the adapter (setListAdapter(adapter)) was happening before the background process could download the rss feed.
Moving it to the onPostExecute() method of the AsyncTask class sorted it out.
I’m glad you figured what’s going on, on your own.
@robbiemc : did your RSS app run without the Async class ?
In other words, I try to run it on Andoid 4.0.3 API Level 15 emulator without the Async class and I got the errors listed above
Could u help me out and post the PostTask class.
T.hanks
Everything between the try and catch clauses went inside the doInBackground method of the AsyncTask class.
My onPostExecute method inside the same class looks like:
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, _headlines);
setListAdapter(_adapter);
doInBackground is a method which returns String object
what do you return ?
Judging by the article with AsyncTasks , onPostExecute takes as parameter what doInBackground returns
Nervermind. I figure it out. T.hanks also for the tutorial regarding async tasks. Great tutorial.
Would definetely recommend it ! Thumbs up
Thanks,
Glad that you figured it out!
How do you guys test your code and what IDE are you using ?
I use Eclipse as the IDE. The code is tested on the emulator first, then on a real device (usually at the end of development, or at the end of development of a specific piece of funtionallity.)
very helpfull thanx so much,,,
Hy, i have one problem, this is great code, but variable called List doesnt workd for me in java eclipse, please help me,
I am following your guide but i have error in funtion “setListAdapter(adapter);” i can’t find funtion setListAdapter, can you show me it? thanks for all
give me clearly information for make news rss feeds or code in android
protected void onListItemClick(ListView l, View v, int position, long id) {
Uri uri = Uri.parse(links.get(position));
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
In this method i have received an error on this line:” Uri uri = Uri.parse(links.get(position));”. The error Description
The method parse(String) in the type Uri is not applicable for the arguments (Object) SimpleRssReaderActivity.java /SimpleRssReader/src/com/SimpleRssReader
Please assist asap
I have been facing few unexpected problems:
ArrayAdapter, ArrayList, IOException, MalformedURLException, URL cannot be resolved to a type
XmlPullParser cannot be resolved
XmlPullParserException cannot be resolved to a type
XmlPullParserFactory cannot be resolved
XmlPullParserFactory cannot be resolved to a type
Please guide, for I’m a noob
You should import their appropriate packages.
If you are using Eclipse then go to Source -> Organize imports to automatically import all required classes. Or you may use the CTRL+SHIFT+O shortcut which does the same.
Source Code files please, if possible
Thanks a lot for this tutorial !! you just saved my life!
Indeed i had to create this kind of application for my studies… and i had no idea how to do it!
Now i understand how to do it and it’s just cool !! thanks a lot for your explanations, they are perfect!!!
Android and me it’s not a love story i suppose… ^^
cannot call getInputStream(url) directly (line 13), then I change to
url.openConnection().getInputStream(). Is this ok?
I have a problem, when I run it on the emulator is just says “Unfortunately SimpleRssReader has stopped” and then shuts down
There may be many causes why it crashes, like not declaring the permissions in the AndroidManifest file.
But I suppose this is because the SimpleRssReader is trying to perform a network operation from the UI thread. In version 2.2 this was possible, but in later versions this is prohibited. You should use an AsyncTask to access the network and parse the RSS.
Thank you
I’m having problems with the code in Step 7:
Multiple markers at this line
- The method onListItemClick() of type SimpleRssReaderActivity must override a superclass
method
- Syntax error on token “1″, invalid VariableDeclaratorId
- ListView cannot be resolved to a type
Make sure your activity extends ListActivity instead of Activity, and import corresponding packages.
if you mean me, yes i extend listactivity… an im running it with version 2.3.3. if this is a case
It does… I’m very confident that I followed along exactly. I’m really not sure what’s going on or why this isn’t working for me.
Basically this means that Uri.parse() expects a String, but your are giving it an object of another type.
What I can say is to make sure that when parsing the RSS, you add to the List a String, it
should be like this: links.add(xpp.nextText());
Thank you for the good writeup. It in fact was a amusement account it.
Look advanced to far added agreeable from you! By the way,
how can we communicate?
Do you mind if I quote a few of your posts as long as I provide credit
and sources back to your webpage? My website is in the very same niche
as yours and my visitors would truly benefit from a lot of the information you provide here.
Please let me know if this ok with you. Cheers!
Sure, as long as you refer to the original article it’s OK.
the app isn’t runnig for android 4.0.3
Didnt work here on android 4.0 friend… :/
As I already stated here in comments, the tutorial was built for Android 2.2 and now is a bit outdated. Starting with Android 3.0 you are no longer allowed to perform network operations on the UI thread. If you do, you get a NetorkOnMainThreadException. You should access the RSS from an AsyncTask. That is why on 2.2 works, but on 4.0 crashes.
i have an unknown exception
#1 Here Thx a lot!
Hi Andy…thnks…..helpd me in my project….works perfectly
Hi, thanks for this tutorial.
I doing like this instead : list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView arg0, View arg1, int position,
long arg3) {
Intent intent = new Intent(Playlist.this, PlaySermon.class );
startActivity(intent);
}
});
And its working fine since I wanna play the streamed link in a mediaplayer.
My problem now is to bring my URL to the other class and send it into the mediaplaying play button. How can I do it?
Is there anyway to store the URL I have taken out from the xml file into getters or something and use it in the other class.
I have tried but nothing is working for me.
Thnkas
Not sure if I understood your question, but if you want to retrieve the URL from the XML, and then pass it to another method or class, you could put the url into a variable, and then pass that variable to the corresponding method as an argument, or to your class as an argument in constructor.
Brilliant tutorial! Works like a charm
thanks so much!
I tried to follow your tutorials but I encountered a runtime exception error that says “Your content must have a ListView who se id attribute is ‘android.R.id.list’”. I’m going nuts even if I changed the ID excactly on what the error said and felt nothing.
Thanx a lot for the Post!!! I have a little problm, RSS feed app works perfectly on eclipse simulator , but i can’t run it on my phone , android 4.0 ICS .
The tutorial is a bit outdated, starting with Android 3.0 you are no longer allowed to perform network operations on the UI thread. You should access the RSS from an AsyncTask. That is why on 2.3 works, but on 4.0 crashes.
U have to select ur Phone’s Android version or below in “Minimum required SDK” at Eclipse
it works on AVD 2.3 in simulator
Genuinely no matter if someone doesn’t understand after that its up to other viewers that they will help, so here it happens.
hi, i went through your tutorial step by step and found one error while parsing URL to string…Can u please help me out with this?
Please update the Tutorial for the latest version of Android. Thank you A LOT friend!!
I am new to this so sorry for the stupid question, but when you say “Open the SimpleRSSReaderActivity”, how do I do this?
Code is working perfectly.i got the output.Thank u Andy Res.All u have to do is add this
try {
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy =
new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
URL url = new URL(“http://feeds.pcworld.com/pcworld/latestnews”);
———————————–
also
List headlines;
List links;
@SuppressLint(“NewApi”)
// Binding data
ArrayAdapter adapter = new ArrayAdapter(this,
android.R.layout.simple_list_item_1, headlines);
setListAdapter(adapter);
how ican connent between list view and this
thanks
can u get all filess of project in zip file to download it please
First of all thanks for this awesome example it was indeed a gr8 help…for all those who are trying to get it run on API 17 ..all u need to do is first remove the setContentview from the oncreate() method as you will be using one of android’s inbuilt layout..then put all the content of the 5th point under the do in background method of the class extending AsyncTask … then just put the adapter code(i.e //Binding data part ) in the post execute method….lastly for the onclick listener method just modify the URi code as Uri uri = Uri.parse(String(links.get(position))); ..and dats it…..Thanx also to all the people who have replied coz I found my answers by reading through your experiences..M barely a few weeks old to this platform..and you all have been a gr8 help to me…
I see, so you parse toString?
The problem I have is specifically this line.
“setListAdapter(adapter);”
return type for method is missing and adapter cannot be resolved to a type. Please help thanks.
Hi,
i am getting error in these lines…
List headlines;
List links;
List cannot be resolved a type.
headlines = new ArrayList();
links = new ArrayList();
Multiple markers at this line. List cannot be resolved a type. ArrayList cannot be resolved a type.
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(false);
XmlPullParser xpp = factory.newPullParser();
XmlPullParserFactory factory cannot be resolved a type.
please help. i am new to android development. what are the classes i have to import?
can you please post the complete “SimpleRssReaderActivity.java ” file…
thanks
i have used source organized imports. some Errors cleared.
but still one more error…
protected void onListItemClick(ListView l, View v, int position, long id) {
Uri uri = Uri.parse(links.get(position));
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
The method parse(String) in the type Uri is not applicable for the arguments (Object)
Please help.
Uri uri = Uri.parse(links.get(position));
I am getting error on that line
The method parse(String) in the type Uri is not applicable for the arguments (Object)
I even did that
Uri uri = Uri.parse(links.get(position).toString());
So no build error but runtime error
how to solve this…
Thanks
As the error says, the method accepts a String but you are passing to it an Object. You would need to cast that object to String.
Still have this error