[英]Error while opening port in Java
尝试打开现金抽屉时出现以下错误。
Error loading win32com: java.lang.UnsatisfiedLinkError: C:\\Program Files\\Java\\jdk1.6.0_15\\jre\\bin\\win32com.dll: Can't load IA 32-bit .dll on a AMD 64-bit platform
我正在使用的代码如下
import javax.comm.*;
import java.util.*;
/** Check each port to see if it is open. **/
public class openPort {
public static void main (String [] args) {
Enumeration port_list = CommPortIdentifier.getPortIdentifiers ();
while (port_list.hasMoreElements ()) {
// Get the list of ports
CommPortIdentifier port_id =
(CommPortIdentifier) port_list.nextElement ();
// Find each ports type and name
if (port_id.getPortType () == CommPortIdentifier.PORT_SERIAL)
{
System.out.println ("Serial port: " + port_id.getName ());
}
else if (port_id.getPortType () == CommPortIdentifier.PORT_PARALLEL)
{
System.out.println ("Parallel port: " + port_id.getName ());
} else
System.out.println ("Other port: " + port_id.getName ());
// Attempt to open it
try {
CommPort port = port_id.open ("PortListOpen",20);
System.out.println (" Opened successfully");
port.close ();
}
catch (PortInUseException pe)
{
System.out.println (" Open failed");
String owner_name = port_id.getCurrentOwner ();
if (owner_name == null)
System.out.println (" Port Owned by unidentified app");
else
// The owner name not returned correctly unless it is
// a Java program.
System.out.println (" " + owner_name);
}
}
} //main
} // PortListOpen
该错误明确指出您的dll是32位。 JVM也应该是32位。
如前所述,您正在使用的Java Communications API (2.0,不是Windows尚不可用的当前3.0)适用于Windows 32位,因此win32com.dll必须与32位JRE / JDK而非64位JRE /一起使用。 JDK。 尝试使用JDK 1.6.0_15 32位版本。
好像您在64位平台上使用32位JDK。 尝试64位JDK! 或者,如果可用,请安装64位版本的API。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.