How to create a J2ME MIDP RSS Reader application with NetBeans 4.0Contributed 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:
This tutorial will cover these subjects:
Designing the application
The project has five source code files:
This tutorial won't deeply explain the the functionality of each class. You can aquire source files here. RequirementsYou 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
Now the project node in Projects window should look like this:
Create new Java Packages for source files and application icon
Now you have requred packages for the source code files and the application icons.
Configure the project
Now we are going to add a reference to kXML library that you have downloaded on your computer. Now you have added the reference to kXML library and you can use the kXML parser in your application. Creating the source code filesNow 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. Add an icon to your application
Now we are going to add an icon to our Mobile application.
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.
Using Obfuscation to reduce MIDlet file size
Building the project
Now we are going to build the project. Alternatively you could select Build > Build Main Project from the main menu.
Take a notice that jar file's size is almost 24kb.
Take a notice that jar file's size is reduced to 15kb bytes.
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
Alternatively you could select Run > Run Main Project 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.
The end
Conclusion and development ideasThis 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 :)
|