Sei sulla pagina 1di 8

J2ME MIDP RSS Reader Tutorial for NetBeans 4.

Search:

HOME / Docs & Support

How to create a J2ME MIDP RSS Reader application with NetBeans 4.0
Contributed by Tommi Laukkanen as part of the Win With NetBeans comptetition This tutorial will show you how to create a J2ME MIDP RSS Reader application with NetBeans 4.0. With RSS Reader you can read RSS feeds with your mobile device. This application is designed to work with MIDP 1.0 so it is also compatible with older devices. In case you are new to RSS, it stands for Really Simple Syndication. RSS is a lightweight XML format designed for sharing headlines and other content like blogs and news. You can for example get the latest NetBeans.org news as a RSS feed from here. Here are some screenshots of this application in action:

Learning Trails
Basic Java Programming Java GUIs and Project Matisse Web Applications Java EE Applications Mobile Applications SOA Applications and UML NetBeans Modules and Rich-Client Applications

Docs for Packs


Mobility Pack Visual Web Pack Enterprise Pack Profiler

Launch icon

Bookmarks list

Loading form

http://www.netbeans.org/kb/articles/rss-reader.html (1 of 8)09/12/2006 06:34:01

J2ME MIDP RSS Reader Tutorial for NetBeans 4.0

Headers list

Topic form

This tutorial will cover these subjects:


q

Creating new mobile application project with NetBeans 4.0 Configuring your NetBeans 4.0 project to allow the usage of 3rd party libraries (eg. kXML 2) Using obfuscator to reduce distributable jar file's size with NetBeans 4.0 Running mobile application on emulator with NetBeans 4.0

Designing the application


The project has five source code files:
q

RssFeed.java, The code for the RSS feed class RssItem.java, The code for the RSS feed item class RssFeedParser.java, The code for the RSS feed parser class Settings.java, The code for the settings utility class RssReaderMIDlet.java, The code for the MIDlet class

This tutorial won't deeply explain the the functionality of each class. You can aquire source files here.

Requirements
You must have NetBeans IDE 4.0 and the NetBeans Mobility Pack 4.0 installed before you can start J2ME MIDP development. See the J2ME MIDP Development Download page for instructions on downloading and installing the complete environment. You also need to download kXML mobile class library. The latest version of the library on time of writing was 2.1.9. You can download the latest kXML release here. Download the kxml2-min. jar to any folder on your computer.

Creating a Mobile Class Library project


Create a new Mobile Application project
1. Choose File > New project (Ctrl-Shift-N). Under Categories, select Mobile 2. Select Mobile Application under Projects. Click Next.

http://www.netbeans.org/kb/articles/rss-reader.html (2 of 8)09/12/2006 06:34:01

J2ME MIDP RSS Reader Tutorial for NetBeans 4.0

3. Under Project Name, type RSS Reader. 4. Change the Project Location to any folder on your computer. 5. Select Set as Main Project checkbox 6. Unselect Create Hello MIDlet checkbox 7. Click Finish. Now the project node in Projects window should look like this:

Create new Java Packages for source files and application icon
1. Right-click the RSS Reader project node in Projects window and select New > Java Package

2. Under Package Name, type RssReader. 3. Click Finish. 4. Repeat the previous actions and add icons package Now you have requred packages for the source code files and the application icons.

Configure the project


1. Right-click the RSS Reader project node in Projects window and select Properties.
http://www.netbeans.org/kb/articles/rss-reader.html (3 of 8)09/12/2006 06:34:01

J2ME MIDP RSS Reader Tutorial for NetBeans 4.0

2. Select Application Descriptor > Attributes. 3. Select MIDlet-Vendor line under General Attributes list and click Edit. 4. Under Value, type your own name. 5. Close the edit window by clicking OK button. Now we are going to add a reference to kXML library that you have downloaded on your computer. 6. Select Build > Libraries & Resources. 7. Click Add Jar/Zip. 8. Browse to downloaded kxml2-min.jar file Now you have added the reference to kXML library and you can use the kXML parser in your application.

Creating the source code files


Now we are going to create the source code for this project. Now you should have downloaded the existing source code files, as mentioned in the requirements section. You should now move them to your project folder's src/RssReader subfolder. After you have copied the source code files into the RssReader folder, the Project window's RssReader package should look the same as in the picture below. It could take a few second to refresh the packages content in the project window.

If you wouldn't have the source code ready, then you would use New > Java Class or New > Midlet features and then write your own code.

http://www.netbeans.org/kb/articles/rss-reader.html (4 of 8)09/12/2006 06:34:01

J2ME MIDP RSS Reader Tutorial for NetBeans 4.0

Add an icon to your application


Now we are going to add an icon to our Mobile application. 1. Right-click picture below and download it to RSS Reader project's src/icons/ subfolder

2. Right-click the RSS Reader project node in Projects window and select Properties. 3. Select Application Descriptor > MIDlets. 4. Click Add. The NetBeans IDE is smart enough to fill up all the fields as you only need to select the icon that you want your application to have. 5. Under MIDlet Icon, select /icons/rss.png.

6. Close both windows by clicking the OK button.

Using Obfuscation to reduce MIDlet file size


Building the project
Now we are going to build the project.
http://www.netbeans.org/kb/articles/rss-reader.html (5 of 8)09/12/2006 06:34:01

J2ME MIDP RSS Reader Tutorial for NetBeans 4.0

1. Press F11 to build your project. Alternatively you could select Build > Build Main Project from the main menu. 2. Right-click RSS_Reader.jar on the Files window and select Properties.

Take a notice that jar file's size is almost 24kb.

3. Right-click RSS Reader project node and select Properties. 4. Select Build > Obfuscating 5. Slide the Obfuscation Level to maximum value (=High). 6. Click OK button. 7. Rebuild the application pressing F11 8. Right-click RSS_Reader.jar on the Files window and select Properties. Take a notice that jar file's size is reduced to 15kb bytes.

http://www.netbeans.org/kb/articles/rss-reader.html (6 of 8)09/12/2006 06:34:01

J2ME MIDP RSS Reader Tutorial for NetBeans 4.0

As the memory usage in smaller mobile devices is a critical issue, therefore the obfuscating is very important part of the mobile application development. We have now saved almost 10 kb memory only by changing Obfuscator settings on our NetBeans IDE.

Using the emulator


Run the project
1. Press F6 to Run the main project Alternatively you could select Run > Run Main Project 2. Press Launch button on default emulator The RSS Reader is now running and you can use it to view RSS feeds. The following screenshots have been taken from Sony Ericsson emulator.

Launch icon

Bookmarks list

Loading form

http://www.netbeans.org/kb/articles/rss-reader.html (7 of 8)09/12/2006 06:34:01

J2ME MIDP RSS Reader Tutorial for NetBeans 4.0

Headers list

Topic form

The end
Conclusion and development ideas
This concludes the J2ME MIDP RSS Reader tutorial. You may now easily continue on developing this application by adding new features. You could for example add a support for Atom XML feeds. Please keep me informed what ever you do with this code :)

Shop

SiteMap

About Us

Contact

Legal

By use of this website, you agree to the NetBeans Policies and Terms of Use

http://www.netbeans.org/kb/articles/rss-reader.html (8 of 8)09/12/2006 06:34:01

Potrebbero piacerti anche