我試圖使用scanf
功能與JNA功能scanf函數:與JNA
package importDLLs;
import com.sun.jna.Library;
import com.sun.jna.Native;
public class JNATest {
public interface CLibrary extends Library {
CLibrary clib = (CLibrary) Native.loadLibrary("msvcrt", CLibrary.class);
void printf(String format, Object... args);
int sprintf(byte[] speicher, String format, Object...args);
int scanf (String format, Object... args1);
}
public static void main(String[] args) {
CLibrary.clib.printf("Hello World");
String test= null;
args = new String[2];
args[0]="This is a test";
args[1]="and another one";
for (int i = 0; i < args.length; i++){
CLibrary.clib.printf("\nArgument %d : %s",i, args[ i ]);
}
CLibrary.clib.printf("\nBitte Namen eingeben");
CLibrary.clib.scanf("%s", test);
CLibrary.clib.printf("\nyour name is %s",test);
}
}
我是新來的這一點,我也讀了很多關於JNA。但我無法弄清楚如何使用它。 printf
函數沒有問題。
這是我得到的錯誤,當我啓動它,並在我寫了一些東西后,控制檯。
已經由Java運行時環境中檢測到致命錯誤:
EXCEPTION_ACCESS_VIOLATION(0000005)中的PC = 0x000007fefe531435, PID = 10168,TID = 2964
JRE版本:7.0_03-B05 Java虛擬機:爪哇熱點(TM)64位服務器VM (22.1-B02混合模式窗口-AMD64壓縮糟糕)有問題的幀: C [MSVCRT.DLL + 0x61435]
無法寫入核心轉儲。小型轉儲默認情況下不啓用在Windows
的 客戶端版本包含更多信息的錯誤報告文件保存爲: ***** \ URC實驗室\ hs_err_pid10168.log
如果你想提交一個錯誤報告,請訪問:
http://bugreport.sun.com/bugreport/crash.jsp
崩潰發生在本地代碼中Java虛擬機之外的 。看有問題的框架 報告錯誤的地方。
程序輸出:
Hello World Argument 0 : This is a test Argument 1 : and another one your name is
爲什麼我得到的錯誤,以及如何解決呢?
歡迎來到Stack Overflow!雖然這段代碼可能有助於解決這個問題,但它並沒有解釋_why_和/或_how_它是如何回答這個問題的。提供這種附加背景將顯着提高其長期價值。請[編輯]您的答案以添加解釋,包括適用的限制和假設。 – 2016-10-05 20:26:52