Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6841011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:54:50+00:00 2026-05-26T23:54:50+00:00

I compiled this code with Sun Java ME Platform SDK 3.0 , the code

  • 0

I compiled this code with Sun Java ME Platform SDK 3.0, the code will listen to serial port:

import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;
import gnu.io.SerialPortEvent;
import gnu.io.SerialPortEventListener;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Enumeration;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.*;

public class SerialPortMidlet extends MIDlet implements CommandListener, SerialPortEventListener
{
    private Command download = new Command("download", Command.ITEM, 0);
    private Command exit = new Command("exit", Command.ITEM, 1);
    private Form f = new Form("test serial port");
    private TextField ports = new TextField("data : ","",1000,TextField.ANY);
    private static final String PORT_NAMES = "COM4";
    private SerialPort serialPort;
    private InputStream input;
    private OutputStream output;
    private static final int TIME_OUT = 2000;
    private static final int DATA_RATE = 9600;

    public SerialPortMidlet()
    {
        f.append(ports);
        f.addCommand(download);
        f.addCommand(exit);
        f.setCommandListener(this);
    }
    public void startApp() {
        Display.getDisplay(this).setCurrent(f);
        initialize();
    }
    public void pauseApp() {
    }
    public void destroyApp(boolean unconditional) {
        notifyDestroyed();
    }
    public void commandAction(Command c, Displayable d) {
        if (c == exit)
            destroyApp(true);
    }
    public void initialize() {
        CommPortIdentifier portId = null;
        Enumeration portEnum = CommPortIdentifier.getPortIdentifiers();
        while (portEnum.hasMoreElements()) {
            CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement();
            if (currPortId.getName().equals(PORT_NAMES)) {
                portId = currPortId;
            }
        }
        if (portId == null) {
                System.out.println("Could not find COM port.");
                return;
        }
        try
        {
            // open serial port, and use class name for the appName.
            serialPort = (SerialPort) portId.open(this.getClass().getName(), TIME_OUT);

            // set port parameters
            serialPort.setSerialPortParams( DATA_RATE,
                                            SerialPort.DATABITS_8,
                                            SerialPort.STOPBITS_1,
                                            SerialPort.PARITY_NONE );

            // open the streams
            input = serialPort.getInputStream();
            output = serialPort.getOutputStream();

            // add event listeners
            serialPort.addEventListener(this);
            serialPort.notifyOnDataAvailable(true);
        }
        catch (Exception e) {
                System.err.println(e.toString());
        }
    }
    public synchronized void close() {
        if (serialPort != null) {
            serialPort.removeEventListener();
            serialPort.close();
        }
    }
    public void serialEvent(SerialPortEvent oEvent) {
        if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE)
        {
            try {
                    int available = input.available();
                    byte chunk[] = new byte[available];
                    input.read(chunk, 0, available);

                    // Displayed results are codepage dependent
                    ports.setString(new String(chunk));
                    System.out.print(new String(chunk));
            } catch (Exception e) {
                    System.err.println(e.toString());
            }
        }
    }
}

And the output shows :

pre-init:
pre-load-properties:
exists.config.active:
exists.netbeans.user:
exists.user.properties.file:
load-properties:
exists.platform.active:
exists.platform.configuration:
exists.platform.profile:
basic-init:
cldc-pre-init:
cldc-init:
cdc-init:
bdj-init:
post-init:
init:
conditional-clean-init:
conditional-clean:
pre-clean:
clean-timestamp:
clean-preprocessed:
clean-classes:
Deleting directory C:\Documents and Settings\Ambre-28\Mes documents\JavaMESDKProjects\testPortSerie\build\compiled
clean-obfuscated:
clean-preverified:
clean-manifest:
clean-jar:
clean-jad:
clean-javadoc:
clean-j9:
Deleting: C:\Documents and Settings\Ambre-28\Mes documents\JavaMESDKProjects\testPortSerie\convert883343865
post-clean:
do-clean:
clean:
deps-jar:
pre-preprocess:
do-preprocess:
post-preprocess:
preprocess:
pre-compile:
extract-libs:
Created dir: C:\Documents and Settings\Ambre-28\Mes documents\JavaMESDKProjects\testPortSerie\build\compiled
Expanding: D:\rxtx-2.1-7-bins-r2\RXTXcomm.jar into C:\Documents and Settings\Ambre-28\Mes documents\JavaMESDKProjects\testPortSerie\build\compiled
do-compile:
Compiling 1 source file to C:\Documents and Settings\Ambre-28\Mes documents\JavaMESDKProjects\testPortSerie\build\compiled
C:\Documents and Settings\Ambre-28\Mes documents\JavaMESDKProjects\testPortSerie\src\SerialPortMidlet.java:16: cannot access java.util.EventListener
class file for java.util.EventListener not found
public class SerialPortMidlet extends MIDlet implements CommandListener, SerialPortEventListener
C:\Documents and Settings\Ambre-28\Mes documents\JavaMESDKProjects\testPortSerie\src\SerialPortMidlet.java:34: cannot find symbol
symbol  : variable this
location: class SerialPortMidlet
        f.setCommandListener(this);
C:\Documents and Settings\Ambre-28\Mes documents\JavaMESDKProjects\testPortSerie\src\SerialPortMidlet.java:37: cannot find symbol
symbol  : variable this
location: class SerialPortMidlet
        Display.getDisplay(this).setCurrent(f);
C:\Documents and Settings\Ambre-28\Mes documents\JavaMESDKProjects\testPortSerie\src\SerialPortMidlet.java:65: cannot find symbol
symbol  : variable this
location: class SerialPortMidlet
            serialPort = (SerialPort) portId.open(this.getClass().getName(), TIME_OUT);
C:\Documents and Settings\Ambre-28\Mes documents\JavaMESDKProjects\testPortSerie\src\SerialPortMidlet.java:78: cannot find symbol
symbol  : variable this
location: class SerialPortMidlet
            serialPort.addEventListener(this);
C:\Documents and Settings\Ambre-28\Mes documents\JavaMESDKProjects\testPortSerie\src\SerialPortMidlet.java:92: cannot access java.util.EventObject
class file for java.util.EventObject not found
        if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE)
6 errors
C:\Documents and Settings\Ambre-28\Mes documents\JavaMESDKProjects\testPortSerie\nbproject\build-impl.xml:246: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 7 seconds)

The system is Windows XP and I already added the RXTXcomm.jar to the Libraries & Resources of the project property. So why is there these errors?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:54:51+00:00Added an answer on May 26, 2026 at 11:54 pm

    You cannot use external dlls or JNI to extend the feature set of J2ME VM, unlike J2SE. VM is supplied by the vendor or OEM and publish the level of support it has (such as JTWI compliance etc). So, in short, serial port access cannot be obtained by using Rxtx library.

    However, serial port can be accessed by Generic I/O framework:

    CommConnection sc = (CommConnection)Connector.open("comm:0;baudrate=9600");
    

    However, support for comm is optional and vendor might not implement it. You will need to cross check with device’s documentation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a GWT solution. (so this is java code that is then compiled to
This code, when compiled in xlC 8.0 (on AIX 5.3), produces the wrong result.
i am using this code to check if my glsl shader compiled fine. glGetObjectParameterivARB(obj,
I wrote this simple C code and compiled it using Visual Studio 2010, with
Hi everyone i was working with memcache, and when i compiled this code i
this is my first servlet ever. here is it's code. import javax.servlet.*; import javax.servlet.http.*;
I saved this code in FirstApp.java: class FirstApp { public static void main (String[]
I have this line of Java code: return getValue() != null ? getValue() :
I am trying this code in java: try { String url = http://url.com/file.ext; InputStream
I think this has something to do with a lawsuit with Sun over Java

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.