我正在尝试读取和写入并行端口,我用 C 实现了写入和读取,现在我想将该代码导入 java GUI 应用程序。我设法将 C .so 文件包含到 java 项目中,当直接在 Java 解决方案 main() 方法中调用函数时,它们工作得很好。
我试图在按下按钮时调用本机函数,但它不起作用,应用程序崩溃。我以 root 身份运行应用程序,需要 root 权限来更改和读取并行端口值。
我如何尝试调用本机函数:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try
{
int portNR=Integer.parseInt(jTextField1.getText());
int value=Integer.parseInt(jTextField2.getText());
ParalellComanderApp.setPort(portNR,value );
}
catch (Exception e)
{
System.err.println(e.getMessage());
}
}
C中的Native函数:
JNIEXPORT void JNICALL Java_paralellcomander_ParalellComanderApp_setPort
(JNIEnv *env, jobject obj, jint port, jint value)
{
outb(value,MAIN_PORT+port);
printf("Setting port %d to value %d\n",port,value);
}
崩溃消息:
A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f00adaf9833, pid=6516, tid=139640785835776
#
# JRE version: 6.0_23-b23
# Java VM: OpenJDK 64-Bit Server VM (20.0-b11 mixed mode linux-amd64 compressed oops)
# Derivative: IcedTea6 1.11pre
# Distribution: Ubuntu oneiric (development branch), package 6b23~pre10-0ubuntu5
# Problematic frame:
# C [libAccessParalel.so+0x833] inb+0x17
#
# An error report file with more information is saved as:
# /home/bari/NetBeansProjects/ParalellComander/dist/hs_err_pid6516.log
#
# If you would like to submit a bug report, please include
# instructions how to reproduce the bug and visit:
# https://bugs.launchpad.net/ubuntu/+source/openjdk-6/
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
对不起,很长的帖子。有谁能够帮我?