[英]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.