Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Regular Contributor
pavankumarragi
Posts: 63
Registered: ‎08-30-2012
My Device: 9900

BlackBerry java Rss Reader

[ Edited ]

hi,

    i developed Rss Reader Example,my requirement is  to fetch TITLE AND LINK values from Rss xml File and display it on my output console,i have used System.out.println,i am not able to retrieve the title and link values from Rss File,can any one help me what should i make changes in my code?

here my code:

 

public class RssMain extends UiApplication {
RssMain theApp;
public static void main(String[] args)
{
// create an instance of our app
RssMain theApp = new RssMain();
// "run" the app
theApp.enterEventDispatcher();
}
// app constructor
public RssMain()
{
// create an instance of the main screen of our application
RssScreen screen = new RssScreen();
// make the screen visible
UiApplication.getUiApplication().pushScreen(screen);
}
class RssScreen extends MainScreen{

public RssScreen(){
String rssUrl = "http://twitter.com/statuses/user_timeline/27756405.rss";
String[][] urlData = RSSHandler.getURLFromRSS(rssUrl);
for (int i = 0; i < urlData.length; i++) {
String title = urlData[0][i];
String url = urlData[1][i];
System.out.println("TITLE "+title);//i want to print on my console

 System.out.println("URL "+url);

}
}

}

}

 

 

 

 

 

import java.io.IOException;
import java.io.InputStream;

import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import net.rim.blackberry.api.browser.Browser;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.util.Arrays;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class RSSHandler extends DefaultHandler {
boolean isItem = false;
boolean isTitle = false;
boolean isLink = false;
String[] title = new String[] {};
String[] link = new String[] {};
String value = "";

public void startElement(String uri, String localName, String name,
Attributes attributes) throws SAXException {
if (!isItem) {
if (name.equalsIgnoreCase("item"))
isItem = true;
} else {
if (name.equalsIgnoreCase("title"))
isTitle = true;
if (name.equalsIgnoreCase("link"))
isLink = true;
}
}

public void characters(char[] ch, int start, int length)
throws SAXException {
if (isTitle || isLink)
value = value.concat(new String(ch, start, length));
}

public void endElement(String uri, String localName, String name)
throws SAXException {
if (isItem && name.equalsIgnoreCase("item"))
isItem = false;
if (isTitle && name.equalsIgnoreCase("title")) {
isTitle = false;
Arrays.add(title, value);
value = "";
}
if (isLink && name.equalsIgnoreCase("link")) {
isLink = false;
Arrays.add(link, value);
value = "";
}
}


public static String[][] getURLFromRSS(String url) {
InputStream is = null;
HttpConnection connection = null;
RSSHandler rssHandler = new RSSHandler();
try {
connection = (HttpConnection) Connector.open(url);
is = connection.openInputStream();
try {
SAXParser parser = SAXParserFactory.newInstance()
.newSAXParser();
parser.parse(is, rssHandler);
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (is != null)
is.close();
if (connection != null)
connection.close();
} catch (IOException e) {
e.printStackTrace();
}
}
String[][] result = new String[2][];
result[0] = rssHandler.title;
result[1] = rssHandler.link;
return result;
}


}

 

 

 

Please use plain text.
Developer
kamal_nigam
Posts: 434
Registered: ‎07-23-2012
My Device: Blackberry 10

Re: BlackBerry java Rss Reader

If you are using eclipse plug-in for development than you need to run your program in debug mode to see the logs/SOP. Choose debug as option from the eclipse.

Thanks
-------------------------------------------------------------------------------------
Press the Accept as solution Button when u got the Solution
Press Kudo to say thank to developer.
-------------------------------------------------------------------------------------.
Please use plain text.
Developer
simon_hain
Posts: 16,134
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: BlackBerry java Rss Reader

is this still an issue? because your code in http://supportforums.blackberry.com/t5/Java-Development/Blackberry-Rss-Parsing-java/td-p/1899249 looks different.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Regular Contributor
pavankumarragi
Posts: 63
Registered: ‎08-30-2012
My Device: 9900

Re: BlackBerry java Rss Reader

Hii  simon

my requirement is to display image with tilte from Rss Feed?for that i have to create two ListFields or one ListField?and also TwoVectorElements or one? can you hepl me?

 

 

Please use plain text.