J2ME software development for cellular phones
(2002)
Colin Fahey

Motorola T720 cellular phone, shown opened
1. Warning
This document is obsolete! The information in this document might have been valid and useful in the year 2002, but many things have changed in subsequent years! This document should now only be regarded as an interesting historical record of the year 2002. Do not rely on any information or advice in this document. All technical information in this document is very obsolete.
Downloading self-created software, self-created images, and self-created telephone alert melodies (i.e., "ring tones"), was relatively rare and difficult in the year 2002. Sadly, six years later, some cellular phone service providers (including Apple, which provides the exclusive software and "ring tone" portal for the iPhone) still impose restrictions on downloading software, images, and music, because cellular phone service providers enjoyed extremely large financial profits by controlling these types of downloads.
Fortunately, cellular phones such as those featuring the "Android" software platform, will forever end the ability of companies to create and exploit closed markets for such uses of cellular phones. Although consumers willingly purchased cellular phone service plans that included very high costs for downloading software, images, and music, this is because of the limited number of cellular phone service options available.
The economic dynamics that have enabled certain companies to grow to dominate the market should not be interpreted as implicit strong approval by the consumers. As companies start to dominate, and then make it difficult or impossible for competitors to enter the market, the dominating companies can offer products that combine high positive value (e.g., the ability to communicate from anywhere) with high negative value (e.g., high prices for desirable software, images, and music, all of which would otherwise be freely available; thus, the service adds negative value). No consumer is forced to purchase a cellular phone, but there is no doubt that the dominant cellular phone service providers have gradually created conditions that can not be considered a "free market". Therefore, the cellular phone service market has been economically "inefficient" and has been an undue burden on consumers.
Hopefully, requirements that cellular phone service radio frequencies be available to competing services will restore normal market values to data transfer, such that cellular phone service providers are again reduced to mere carriers of data (i.e., only providing bandwidth) rather than information or entertainment providers!
The business of transporting data must be separated from the business of selling data, otherwise there will be an incentive for the data transportation business to block competitors from selling data through the same data transportation channel.
The video game console market suffers from the same problem. The manufacturers of video game console hardware are in the business of creating devices that can display video games, but those same companies also have exclusive control of the transfer of software to those video game consoles. Therefore, there is an incentive for the video game console manufacturers to block competitors from selling software for the video game consoles. If a video game console hardware manufacturer focused on designing and manufacturing hardware that could be sold at a profit (instead of at a significant loss, as with the X-Box and PlayStation and Nintendo video game consoles), then the video game market would thrive, and the quality of the best video games would dramatically improve, and the cost of video games would collapse.
2. Topic index
(1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
(9)
(10)
(11)
(12)
3. J2ME development tools
This section describes how to download development tools that can be used to compile J2ME source code in to class files suitable for mobile devices. Note that the Sun "J2ME Wireless Toolkit", discussed in a later section of this article, requires downloading the Java SDK described in this section.
3.1 JDK 1.4 (or later)
This means you need the conventional Java 2 SDK from Sun. I downloaded and used version 1.4 via the following link:
Here is what the download page looks like:
Start the installation program. Install to the default location ( c:\j2sdk1.4.0_03 ) unless you are able to solve path problems that may arise.
3.2 Connected Limited Device Configuration (CLDC)
I won't pretend to know what this is, but I simply downloaded it from the Sun web site.
Here is what the CLDC main download web page looks like:
Only 1.0.3 was available at the time I visited.
In order to download this, I needed to register with Sun web site. I created the following profile:
Username: anon***anon
Password: nospamplease
Favorite color: blue
Full name: Prof. Anon Nospamplease
I downloaded the following file:
j2me_cldc-1_0_3-fcs-src-b17-winunix-14_sep_2001.zip
I unzipped to the following directory:
I renamed the "cldc-1_0_3-fcs" directory to simply:
cldc ( i.e., the full path is c:\j2me\cldc )
3.3 Mobile Information Device Profile (MIDP)
I won't pretend to know what this is either, but I simply downloaded it from the Sun web site.
Here's what the MIDP main download web page looks like:
I downloaded the following file:
j2me_midp-1_0_3-fcs-src-b26-win-19_sep_2001.zip
I unzipped to the following directory:
I renamed the "midp-1_0_3-fcs" directory to simply:
midp ( i.e., the full path is c:\j2me\midp )
3.4 Configuring tools
3.4.1 Establish paths
Add the following lines to your AUTOEXEC.BAT file:
REM ---- Java Support ----
SET MIDP_HOME=C:\j2me\midp
SET PATH=%PATH%;c:\j2sdk1.4.0_03\BIN;
PATH=C:\WINDOWS;C:\WINDOWS\COMMAND;C:\j2sdk1.4.0_03\BIN;C:\j2me\midp\bin;%PATH%
Then force these variables to be reloaded by running the batch file:
You can also set up these same variables using the Windows environment variable control panel.
Notice that I chose to specify explicit directory paths to my current version of the Java 2 SDK. Therefore, if I upgrade, then I must modify the AUTOEXEC.BAT file to specify the new directories.
3.4.2 Check the Jave 2 SDK binaries
Once the settings above take effect, you should be able to run the Java tool programs from the command prompt without specifying the complete path to the tool programs.
The following command will start the cellular phone device emulator:
The following image shows the cellular phone device emulator:
4. Simple J2ME program
4.1 Write Java code
Using any text editor, a person can type in code, such as for this HelloMIDlet.java source code file:
Here is the code in plain text format:
// File: HelloMIDlet.java
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class HelloMIDlet
extends MIDlet
implements CommandListener
{
private Command exitCommand;
private Display display;
private TextBox t = null;
public HelloMIDlet()
{
display = Display.getDisplay( this );
exitCommand = new Command( "Exit", Command.EXIT, 2 );
t = new TextBox
(
"Hello MIDlet",
"Test string",
256, 0
);
t.addCommand( exitCommand );
t.setCommandListener( this );
}
public void startApp()
{
display.setCurrent( t );
}
public void pauseApp()
{
}
public void destroyApp( boolean unconditional )
{
}
public void commandAction( Command c, Displayable s )
{
if (c == exitCommand)
{
destroyApp( false );
notifyDestroyed();
}
}
}
4.2 Compile *.java code to *.class
Caution: The following command must be on a single line, but has been expanded to several lines of text only for clarity.
(Current directory: C:\HelloMIDlet)
javac
-target 1.1
-d .\
-bootclasspath c:\j2me\midp\classes
HelloMIDlet.java
Note: The "-target 1.1" is necessary to avoid an error in the future "preverify" stage. Apparently this has something to do with a problem with MIDP 1.0.3 support in JDK 1.4.
4.3 Preverify to generate a new *.class file
(Current directory: C:\HelloMIDlet)
preverify -classpath c:\j2me\midp\classes;. HelloMIDlet
This generates a new *.class file in a new subdirectory called "output" (by default).
4.4 Test the new *.class file
(Current directory: C:\HelloMIDlet)
midp -classpath c:\j2me\midp\classes;.\output HelloMIDlet
This starts the phone emulator, indicating that the new "output" directory contains some of the necessary *.class files.
The following image shows the expected result.
4.5 Create a new text file, "manifest.mf", and edit the file
A "manifest.mf" file is essential to getting an actual cellular phone to interpret the contents of a *.jar file. If a proper "manifest.mf" file is not included within the *.jar file, then the cellular phone might successfully download the *.jar file, but might fail to interpret the downloaded file, possibly reporting an error such as "Unsupported Content Type".
The following is an example of a simple "manifest.mf" file.
Here is the "manifest.mf" file as plain text:
MIDlet-1: My_Description,, HelloMIDlet
MIDlet-Name: My_Midlet_Suite
MIDlet-Vendor: Colin Fahey, Inc.
MIDlet-Version: 1.0
MicroEdition-Configuration: CLDC-1.0
MicroEdition-Profile: MIDP-1.0
Notice that the CLDC and MIDP versions are specified in this file. Be very cautious and conservative when editing the various fields in this file. If you get "File Corrupt" errors, then try eliminating all fields that are not shown in this example. Also, put the fields in the order in which they appear in the example. Also, shorten each field value as much as you can, and keep the characters limited to simple letters, digits, periods, and dashes. Some cellular phone services, and cellular phones, can tolerate more variation of field ordering and field contents.
Caution:
When the "jar" program is used to create a *.jar file, and the "manifest.mf" file is specified as the manifest file, the "jar" program reads the manifest file and might add more fields as it creates a file called "MANIFEST.MF" within the output *.jar file. Therefore, if the "MANIFEST.MF" file is extracted from a *.jar file, and is then compared with the original "manifest.mf" file specified during the creation of the *.jar, the two files might be different, with the "MANIFEST.MF" file containing several more fields than the original "manifest.mf" file.
Do not extract a "MANIFEST.MF" file from a *.jar file and attempt to form a new *.jar file using that manifest file. If you extract a "MANIFEST.MF" file from a *.jar file, then be sure to eliminate all fields except for those shown in the example "manifest.mf" file shown above.
Note:
Icons for programs apparently do not appear on the Motorola T720 phone. This is why I did not describe my midlet with an icon. However, the following shows how to set an icon for the program within the manifest file:
MIDlet-1: My_Description, /icon.png, HelloMIDlet
When developing for cellular phones that do display icons for applications, specify the icon filename, and add the icon image file itself to the *.jar file by specifying the file name among the file names of files to be added to the *.jar file.
4.6 Put the "manifest.mf" file and *.class file in to a *.jar file
The following command creates a *.jar file. The *.jar file will contain the specified manifest.mf file, and will contain the *.class files found in the specified directory.
Current directory: C:\HelloMIDlet
jar cfm hi.jar manifest.mf -C .\output HelloMIDlet.class
Complex hypothetical example of creating a *.jar file
Suppose an icon image file (e.g., "icon.png") is to appear in a *.jar file as "/icon.png". (Note: Program icons do not appear on the Motorola T720 cellular phone, but do appear on other cellular phone types, and do appear in the MIDP emulator.)
Suppose there is a directory named "images" with image files (*.png format). Suppose this directory, and all of the images contained in the directory, should be accessible to the Java program by the relative directory /images (such that an image "a.png" would be accessible using the path "/images/a.png").
Suppose all of the *.class files produced by the preverify command are contained in a directory named "verified". For example, the verified version of the main class, "MyApp.class", would be in the "verified" folder, along with the other classes of the program. All of these classes are to be accessible in the root directory of the *.jar file.
The following command will create a *.jar file that achieves the various goals specified in the previous paragraphs. Caution: the command has been expanded to several lines of text here only for clarity. When entering the command at a command prompt, the command must not contain line breaks; otherwise the command interpreter will interpret the entered text as multiple independent commands.
jar
cfmv [Create JAR, Specify JAR Name, Add manifest.mf, Verbose]
MyApp.jar [Name of output JAR file]
manifest.mf [The manifest.mf file]
icon.png [Optional icon, specified by JAD as "/icon.png"]
images [Directory to add to JAR as "/images"]
-C .\verified .
The final part of the command is difficult to understand. It has the following meaning: "Change the current working directory to .\verified, and then put all *.class files found in the relative directory '.' (namely all *.class files in the current working directory) in to the *.jar file." Because the directory had been changed before specifying the path of the classes to put in the *.jar file, the local path will not appear in the relative path when the files are placed in to the *.jar file.
For example, suppose the verified classes are in the following directory:
C:\MyApp\verified
Suppose there are class files such as the following:
C:\MyApp\verified\w.class
Then specifying "-C .\verified ." in the command to create the *.jar file, starting from a current directory of "C:\MyApp", will result in "w.class" being put in the root directory of the *.jar file. </e>
Warning: When the "-C" option is specified, it changes the current working directory at that point of processing the overall sequence of command parameters to the jar command. Therefore, the jar command might complain that it cannot find other files mentioned in command parameters beyond the "-C" option. If this happens, simply move the "-C .\verified ." to be the final parameters of the overall command.
The following shows verbose output of the jar command.
added manifest
adding: icon.png(in = 449) (out= 454)(deflated -1%)
adding: images/(in = 0) (out= 0)(stored 0%)
adding: images/a.png(in = 2463) (out= 2223)(deflated 9%)
adding: images/b.png(in = 1322) (out= 579)(deflated 56%)
adding: images/c.png(in = 3433) (out= 2874)(deflated 16%)
adding: images/d.png(in = 1524) (out= 801)(deflated 47%)
adding: w.class(in = 2570) (out= 1356)(deflated 47%)
adding: MyApplication.class(in = 4714) (out= 2169)(deflated 53%)
adding: x.class(in = 3239) (out= 1429)(deflated 55%)
adding: y.class(in = 14205) (out= 6481)(deflated 54%)
adding: z.class(in = 9448) (out= 5135)(deflated 45%)
4.7 Create and edit a new *.jad file
A *.jad file is necessary so that the cellular phone can describe a computer program to a person before the person decides to download the program. The *.jad file also provides some indirection from the *.jar itself.

An example *.jad file, describing a *.jar file
Here is the example hi.jad file in plain text format:
MIDlet-1: My_Description,, HelloMIDlet
MIDlet-Jar-Size: 1283
MIDlet-Jar-URL: http://www.colinfahey.com/hi.jar
MIDlet-Name: My_Midlet_Suite
MIDlet-Vendor: Colin Fahey, Inc.
MIDlet-Version: 1.0
There are programs which can generate the *.jad file, which makes it easier to update the "MIDlet-Jar-Size:" field each time the *.jar file is changed (and its size changes). If you search the Internet you will find useful J2ME programs.
If the size field doesn't specify the exact byte total of the *.jar file, then the following error might appear after a successful download to a cellular phone: "Download Failed" (download failed).
For the Motorola T720 cellular phone, the following error message might be used to inidcate invalid fields in the *.jad file, or possibly invalid fields in the generated MANIFEST.MF file within the *.jar file: "Failed: File Corrupt" (failed: file corrupt).
Note: If the *.jar file is in the same directory as the corresponding *.jad file on an Internet web server, then the *.jad file can simply indicate the file name of the *.jar file, without specifying a full URL, as in the following example:
MIDlet-Jar-URL: hi.jar
When downloading these files from an Apache Internet web server to a Motorola T720 cellular phone, it is acceptable to not include the full URL. However, when downloading these files from a Yahoo! Internet web server to a Motorola T720 cellular phone, the attempt to download will fail, unless a full URL path to the *.jar file is specified within the *.jad file, as in the following example:
MIDlet-Jar-URL: http://www.colinfahey.com/hi.jar
I do not know the reason for this problem, and I know that this problem does not affect other cellular phones (or cellular phone service providers). Having to specify the full URL for the *.jar file within the *.jad file is obviously inconvenient, because moving the files to different locations on a server would require changing the information in all *.jad files. However, specifying the full URL might make the *.jad more reliable for certain cellular phones and certain cellular phone service providers.
4.8 Test the *.jar file and the *.jad file by executing the program
The following executes the class found in the *.jar file, described by the *.jad file.
(Current directory: C:\HelloMIDlet)
midp -classpath c:\j2me\midp\classes;.\hi.jar -descriptor hi.jad
4.9 References for J2ME, MIDP, CLDC development
Much of what I presented here can be found on many other Internet sites. However, I corrected some errors found on other Internet sites, and added missing details, and presented the complete experience of someone trying to do this stuff. Here are very informative links that helped me get started:
5. Complex J2ME program
5.1 Introduction
The simple program presented in the previous section of this document only has a single source code file, and the program does nearly nothing and thus is not a good example of cellular phone programming.
My friend Sam Robertson wrote an interesting J2ME program that teaches a person to play the card game "Blackjack" (also called "21"). A player is presented with a "dealer card", and the player's pair of cards, and the player must decide what to do: "stay", "hit", "double-down", or "split".
This program has six source code files. The program responds to user input, and does simple drawing and text updates.
5.2 Source code
Click on the following link to get the source code, and the *.jad file, "manifest.mf" file, and a batch file, all in one convenient ZIP file.
sbj.zip
Source code contained in a ZIP file
6090 bytes
MD5: bf3922035b7a4eef24e107d03b7524c9
Extract to an arbitrary directory, but if you extract to "c:\" under Windows, the following example discussion will be even closer to your actual situation.

Extracting sbj.zip to "c:\" creates the directory "c:\sbj"
5.3 Manifest file
File: "manifest.mf":
MIDlet-1: My_Description,, SBJ_MidletT
MIDlet-Name: SBJ_MidletT
MIDlet-Vendor: Sam Robertson
MIDlet-Version: 1.0
MicroEdition-Configuration: CLDC-1.0
MicroEdition-Profile: MIDP-1.0
5.4 The batch file to build the program
The following batch file is rough, but it serves as an illustration of how you might get started with writing your own batch file to build your J2ME program. This example batch file does the following:
(1) Delete the directory containing the old *.class files;
(2) Delete the directory containing the old verified *.class files;
(3) Make a "classes" output directory;
(4) Compile all *.java sources in to *.class files, with output going to the "classes" directory.
(5) Make a "verified" output directory;
(6) Preverify all classes in the "classes" directory, and put the verified classes in the "verified" directory.
(7) Create a *.jar file, and add the mainfest file, and all classes in the "verified" directory;
*(8) Test the program via the preverified classes directly;
*(9) Test the program via the *.jar and *.jad files;
(*...These steps are disabled (by commenting) in my batch file.)

The batch file "build_sbj.bat" for building the program
Here is the same file ("build_sbj.bat") in plain text format:
rmdir /S /Q classes
rmdir /S /Q verified
del /F /Q *.jar
mkdir classes
javac -g:none -target 1.1 -d .\classes -bootclasspath c:\j2me\midp\classes *.java
mkdir verified
preverify -classpath c:\j2me\midp\classes;.\classes -d .\verified .\classes
jar cvfm sbj. jar manifest.mf -C .\verified .
REM midp -classpath c:\j2me\midp\classes;.\verified SBJ_MidletT
REM midp -classpath c:\j2me\midp\classes;.\sbj.jar -descriptor sbj.jad
REM Finished
5.5 Building from the command prompt
Here is the result of running the "build_sbj.bat" batch file at the command line:

Executing the "build_sbj.bat" batch file
Note that the warning messages for the "rmdir" and "del" operations simply indicate that there is nothing to remove.
You can see the new directories (i.e., "classes" and "verified") and the new *.jar file that resulted from running the batch file:

Source code files and new generated file
5.6 *.jad file
To deploy the sbj.jar file, we need to create and edit the sbj.jad file to have the correct *.jar size in the appropriate field:
File: sbj.jad
MIDlet-1: SBJ_MidletT, , SBJ_MidletT
MIDlet-Jar-Size: 7257
MIDlet-Jar-URL: sbj.jar
MIDlet-Name: Sam Blackjack Trainer
MIDlet-Vendor: Sam Robertson
MIDlet-Version: 1.0
MicroEdition-Configuration: CLDC-1.0
MicroEdition-Profile: MIDP-1.0
A person might need to add the complete URL to the *.jar file when the *.jad file is put on an Internet site -- but I discovered (by an experiment) that I was able to avoid mentioning the full URL (i.e., I only specified the *.jar file name by itself). However, putting in the complete URL, but I wanted to let you know what I observed.
5.7 Summary
Having multiple source files in your project is common, and in this section we gave a crude illustration of building multiple classes, followed by packaging and execution.
Please see the following section regarding using Sun Wireless Toolkit, which makes building applications much easier.
6. Sun "Wireless Toolkit (version 1.0.4_01)"
6.1 Introduction
Sun offers a convenient development environment for building and packaging J2ME programs: "Java 2 Platform Micro Edition (J2ME) Wireless Toolkit (version 1.0.4_01)".
(Caution: You need to download the Java 2 SDK 1.4 as described in an earlier section to use this toolkit. Do this now if you don't already have this version of the Java 2 SDK.)
Go to the following Internet site to download the toolkit:
http://java.sun.com/products/j2mewtoolkit/
Caution!!!
Do NOT click on the link "2.0 Beta 1 English" (currently the top download option) if you are doing Motorola T720 development -- because this version has some MIDP-2.0 stuff, and getting around this may be a headache.

Do not download this version! ("2.0 Beta 1 English")
I tried this version, and I eventually got code to compile with lots of messy settings changes, but after all the effort I got a security exception when I tried to execute. Don't bother!
Download the "1.0.4_01 English" version. Here is what the download page looks like:

The Sun J2ME Wireless Toolkit (version 1.0.4_01) download page

The Sun J2ME Wireless Toolkit (version 1.0.4_01) FTP site list
This will download the following file: "j2me_wireless_toolkit-1_0_4_01-bin-win.exe"
Execute this program to install on your system.
6.2 J2ME Wireless Toolkit : launch toolbar
After the toolkit is installed, you can launch it from the "Start" (start) menu system:

Starting the toolbar program
You can also access MIDP-1.0 documentation via the "Documentation" item in this Start (start) menu.

J2ME Wireless Toolkit (version 1.0.4_01) documentation
6.3 J2ME Wireless Toolkit : create project and build

The toolbar is ready. Click "New Project..." to create a new project.

New Project: Type in project name (becomes JAR name and name of new project directory), and type in MIDlet class name (class derived from MIDlet, essentially the main class of your application).

Toolbar: project created. Notice that the console tells you where to put your *.java source files, etc. (e.g., "c:\WTK104\apps\sbj\src", etc)

Click on "Settings..." on the toolbar to get this project settings menu.
Disregard the "MIDlet-Jar-Size" field (with value "100" bytes) for now. We will eventually cause the correct value to get set.

Click on the MIDlets tab of the project settings dialog.
Click on the only row in the table ("MIDlet-1") to highlight and select it. Then click the "Edit" button.

Clear the "Icon" field if you do not have a *.png file to put in your *.jar file.
Do the following:
(1) Project --> Clean : Removes all *.class files;
(2) Build : Builds all *.class files and preverifies;
(3) Project --> Package --> Create Package : Produces *.jar and *.jad

The result of building the *.jar and *.jad
When you do these three steps, the resulting *.jar and *.jad are immediately ready for execution in the local emulator, or for immediate deployment on your Internet site for others to download "Over The Air" (OTA). The *.jar size field in the *.jad file will be correct. Don't forget to do step (3) every single time you rebuild!
Now you can test by hitting the "Run" (run) button.

Hitting "Run" for the project reads the *.jad in to the emulator. You can select the specific MIDlet to launch (typically just one).
Just copy the *.jar and *.jad files from the specified locations (reported by the toolbar's console window during a build of the project), such as:
(From the console window:)
Wrote c:\WTK104\apps\sbj\bin\sbj.jar
Wrote c:\WTK104\apps\sbj\bin\sbj.jad
Put these files directly on to your Internet site without modification, and it should work. Here is what I saw on my cellular phone after downloading this compiled application "over the air" (OTA)

Sam Robertson's Blackjack Trainer (sbj.jar) executing on my cellular phone
7. Offering software on an Internet site
7.1 Ensure that the Internet web server specifies MIME types for *.jar files and *.jad files
If you have an Apache Internet web server, you need to create a file named ".htaccess" within your web site root directory. The ".htaccess" file enables you to override Apache configuration, such as adding or overriding file MIME types. You must add the specify the MIME types corresponding to *.jar files and *.jad files, as shown in the following text file:

My custom ".htaccess" file for the Apache Internet web server. Note: I named this file ".htaccess.txt" merely to make the file easy to edit when using the Windows operating system. The file name must be changed to ".htaccess" before the file can be used with the Apache Internet web server.
Here is my simple .htaccess file as plain text:
AddType text/vnd.sun.j2me.app-descriptor jad
AddType application/java-archive jar
AddType text/vnd.wap.wml wml
Apparently, creating or modifying this file results in an immediate change of Apache server behavior. I guess the Apache server checks the modification date and time of the ".htaccess" file upon each new incoming transaction, and the server reloads that file if the modification date and time has changed.
If you have a different kind of Internet web server, you must determine how to specify MIME types, and you must ensure that *.jar files and *.jad files are assigned the appropriate MIME types.
You will know if the MIME types have not been set up if the cellular phone refuses to download your *.jad file and reports the following error:
"406: Not Acceptable"
7.2 Optionally provide links to the *.jad file within HTML or WML documents
The Motorola T720 J2ME cellular phone with AT&T service is able to download a *.jad file directly, by typing the URL of the *.jad file in to the cellular phone. This is likely to work for other J2ME cellular phones with other cellular phone service providers.
However, it might be more convenient for people to download the *.jad file by selecting a link within an HTML document or within a WML document. (Note: WML is now obsolete. Most cellular phones can now interpret HTML.)

A simple HTML document with a link to a *.jad file

A simple WML (WAP) page with a link to a *.jad file (Note: WML is now obsolete. Most cellular phones can now interpret HTML.)
8. Downloading software from an Internet site
The following images show the exact sequence of actions I did to download and execute the MIDlet developed and deployed as described in the previous sections above. These images are photographs of the screen of my cellular phone.
(1) Main screen: When you open the phone, you see the main screen. Press the center button to go to the main menu.
(2) Main Menu: Move to the item "WebAccess".
(3) WebAccess: Move to the item "Go To URL".
(4) Enter URL: Type in the URL of a *.jad file (or of an HTML document, or of a WML document).
(5) Details; This information was parsed from the *.jad file. Press DOWNLD to download the *.jar file.
(6) Download Complete; Wait for this message to disappear;
(7) Installing; Wait for this message to disappear;
(8) xxxx bytes transferred; Wait for this message to disappear;
(9) Installed; Wait for this message to disappear;
When the WebAccess menu appears again, after the program has been installed, simply exit each menu to return to the main screen.
(1) Main screen: When you open the phone, you see the main screen. Select the "Games & Apps" option via the main menu, or press the downward cursor on the main screen.
(2) Java Powered: Wait for this screen to disappear.
(3) Games & Apps: Select the item with the name of your program!
(4) Yay! Successful execution of your program!
The program appearance on the cellular phone is very similar to the appearance within the emulator.
9. Download error messages and installation error messages
9.1 Motorola T720 (J2ME) error messages
The following errors messages are only relevant to the Motorola T720 (GSM/J2ME) cellular phone.
9.1.1 "Download Failed"
Cause #1
Any file (HTML, JAD, JAR, MID, GIF) over 1644 bytes will cause this error for certain Internet web hosts and servers. Here is a brief list of hosts and servers:
Host / Server Error
=================================================== =================
Apache No
Microsoft Personal Web Server (direct from your PC) No
Earthlink (Apache) No
Yahoo! (custom server) Yes
The problem is due to a flaw in the Motorola T720 GSM/J2ME firmware, which causes downloading files in fragments to fail.
The only apparent solution is to switch Internet web hosts or server type. Other cellular phone types do not have this problem.
Cause #2
The "MIDlet-Jar-Size:" field of a *.jad file does not indicate the exact byte total of the corresponding *.jar file.
9.1.2 "Failed: File Corrupt"
Cause #1
The *.jar file uses API functions which are not available on the specific cellular phone.
For example, MIDP 2.0 functions are not available on the Motorola T720 GSM/J2ME cellular phone (which only has MIDP 1.0 functions). A program might execute within an emulator, but might not execute on the cellular phone.
The solution is to search for MIDP 2.0 functions in the source code and replace them with MIDP 1.0 functions, or eliminate the features which require the MIDP 2.0 functions.
Cause #2
The "manifest.mf" file used to create the *.jar file (via the "jar" utility) contains errors.
Make sure the "manifest.mf" file has the following versions of CLDC and MIDP:
MicroEdition-Configuration: CLDC-1.0
MicroEdition-Profile: MIDP-1.0
The entire "manifest.mf" file should look almost exactly like the following:
MIDlet-1: My_Description,, HelloMIDlet
MIDlet-Name: My_Midlet_Suite
MIDlet-Vendor: Colin Fahey, Inc.
MIDlet-Version: 1.0
MicroEdition-Configuration: CLDC-1.0
MicroEdition-Profile: MIDP-1.0
Each line of text in the "manifest.mf" file, including the final line of the file, should end with a "carraige return" (CR; 13; 0x0d) character followed by a "line feed" (LF; 10; 0x0a) character.
The only fields of the "manifest.mf" file in your own version of the file that should differ from the example shown here are the first three fields listed in the example. The final three fields should be an exact match with the example, and the final two characters of the file should be the "carriage return" and "line feed" after the final field.
Here are possible problems in your version of the "manifest.mf" file:
(1) Your "manifest.mf" file contains characters that are not ASCII characters; (Look at a chart of ASCII characters; any character outside the 0 through 127 range is invalid);
(2) Your "manifest.mf" file does not have a "line feed" (LF) character after each "carriage return" (CR) character at the end of each line;
(3) Your "manifest.mf" file has invisible spaces or tabs at the end of each line before the (CR)(LF) line termination;
(4) Your "manifest.mf" file contains a "Manifest-Version:" line;
(5) The final line of your "manifest.mf" file does not end with a (CR)(LF) line termination, but instead simply reaches the end of the file;
(6) Your "manifest.mf" file does not have the exact fields and exact order of fields as shown in the example above;
(7) Your CLDC version is not exactly 1.0, or your MIDP version is not exactly 1.0;
(8) Your vendor name has characters which are not ASCII characters (e.g., no Unicode characters are allowed);
(9) Your "manifest.mf" file does not have a space after the second comma in the "MIDlet-1:" line;
Perhaps some of the cases listed above do not actually cause problems for many cellular phones, but eliminating all of the cases listed above might enable the download to succeed. After the download is successful, you can experiment with variations of the "manifest.mf" file to discover what other things you can do without causing download errors. When the "manifest.mf" file is modified, it is important to verify that downloading the program continues to work for all target cellular phones and cellular phone service providers. Some phones and services are less flexible than others.
When a "manifest.mf" file is added to a *.jar file via the jar program, the jar program creates a new version of the manifest file within the *.jar file. The generated version of the manifest file within the *.jar file is named "MANIFEST.MF". The jar program might add fields to this file that do not exist in the "manifest.mf" file provided by the programmer. Do not extract a "MANIFEST.MF" file from a *.jar file, unless you are prepared to eliminate some fields and make the remaining fields look exactly like the example "manifest.mf" file shown above.
9.1.3 "Unsupported Content Type"
Cause #1
The cellular phone cannot accept the MIME type reported by the remote server for a specific file.
For example, JPG image files are not supported by the Motorola T720 and will cause this error.
This error can also occur if the MIME type for a supported file type (e.g., GIF, MID, JAD, JAR) is not reported correctly by the server. A person must be very careful to report the exact MIME type for the supported file types.
Cause #2
The file cache on the cellular phone itself needs to be cleared (e.g., Browser Settings -> Clear Cache).
If you recently added MIME types to a remote server, and then attempted to download a file that had previously failed to install due to an incorrect or missing MIME type, then the file cache on the cellular phone might be an obstacle to downloading the file again with the proper MIME type.
It is also possible that the remote file was modified and that the cached version is defective and is preventing the repaired file version from being downloaded as a replacement.
Clearing the browser cache on the cellular phone should ensure that a subsequent download benefits from the latest server configuration (e.g., new MIME settings) and remote file updates.
Cause #3
How to avoid "Unsupported Content type" errors in WAP
If you get an error in WAP saying Unsupported Content type, it's not necessarily due to the content-type setting. Many WAP pages contain special characters, such as Swedish (å ö ä), and in