English 中文(简体)
为什么把这部J2ME代码与RXEK汇编成册?
原标题:Why is there errors when compiling this J2ME code with RXTX?

我将本守则编为。 Sun Java ME平台 SDK 3.0,该守则将聆听系列港口:

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());
            }
        }
    }
}

产出显示:

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 SettingsAmbre-28Mes documentsJavaMESDKProjects	estPortSerieuildcompiled
clean-obfuscated:
clean-preverified:
clean-manifest:
clean-jar:
clean-jad:
clean-javadoc:
clean-j9:
Deleting: C:Documents and SettingsAmbre-28Mes documentsJavaMESDKProjects	estPortSerieconvert883343865
post-clean:
do-clean:
clean:
deps-jar:
pre-preprocess:
do-preprocess:
post-preprocess:
preprocess:
pre-compile:
extract-libs:
Created dir: C:Documents and SettingsAmbre-28Mes documentsJavaMESDKProjects	estPortSerieuildcompiled
Expanding: D:
xtx-2.1-7-bins-r2RXTXcomm.jar into C:Documents and SettingsAmbre-28Mes documentsJavaMESDKProjects	estPortSerieuildcompiled
do-compile:
Compiling 1 source file to C:Documents and SettingsAmbre-28Mes documentsJavaMESDKProjects	estPortSerieuildcompiled
C:Documents and SettingsAmbre-28Mes documentsJavaMESDKProjects	estPortSeriesrcSerialPortMidlet.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 SettingsAmbre-28Mes documentsJavaMESDKProjects	estPortSeriesrcSerialPortMidlet.java:34: cannot find symbol
symbol  : variable this
location: class SerialPortMidlet
        f.setCommandListener(this);
C:Documents and SettingsAmbre-28Mes documentsJavaMESDKProjects	estPortSeriesrcSerialPortMidlet.java:37: cannot find symbol
symbol  : variable this
location: class SerialPortMidlet
        Display.getDisplay(this).setCurrent(f);
C:Documents and SettingsAmbre-28Mes documentsJavaMESDKProjects	estPortSeriesrcSerialPortMidlet.java:65: cannot find symbol
symbol  : variable this
location: class SerialPortMidlet
            serialPort = (SerialPort) portId.open(this.getClass().getName(), TIME_OUT);
C:Documents and SettingsAmbre-28Mes documentsJavaMESDKProjects	estPortSeriesrcSerialPortMidlet.java:78: cannot find symbol
symbol  : variable this
location: class SerialPortMidlet
            serialPort.addEventListener(this);
C:Documents and SettingsAmbre-28Mes documentsJavaMESDKProjects	estPortSeriesrcSerialPortMidlet.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 SettingsAmbre-28Mes documentsJavaMESDKProjects	estPortSerie
bprojectuild-impl.xml:246: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 7 seconds)

该系统是Windows XP,我已在<代码>上添加了RXEKcomm.jar。 Libraries & Resources of the project property. 因此,为什么有这些错误?

最佳回答

你们不能使用外部拖车,也不能使用国家情报和安全局,来扩大J2ME RV的特征,不同于J2SE。 证书由供应商或办公室提供,并公布其提供的支助水平(例如JTWI合规情况等)。 因此,简言之,不能通过利用Rxtx图书馆获得港口的序列接入。

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

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

然而,对comm的支持是选择性的,供应商可能无法执行。 你们需要用装置文件核对。

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签