簡體   English   中英

不使用QAndroidJniObject調用的三個函數之一

[英]One of three functions not being called using QAndroidJniObject

這是從我的自定義java類調用三個函數的代碼:

QAndroidJniObject datafile = QAndroidJniObject::fromString(path);
QAndroidJniObject password = QAndroidJniObject::fromString("asimpletest");

QAndroidJniObject::callStaticObjectMethod("org/qcolocrypt/AESCrypt",
                                          "AESCryptInit",
                                          "(Ljava/lang/String;Ljava/lang/String;)V;",
                                          password.object<jstring>(),
                                          datafile.object<jstring>());


QAndroidJniObject decrypted_data = QAndroidJniObject::callStaticObjectMethod("org/qcolocrypt/AESCrypt",
                                                                             "decrypt",
                                                                             "()Ljava/lang/String;");


QAndroidJniObject fname = QAndroidJniObject::callStaticObjectMethod("org/qcolocrypt/AESCrypt",
                                                                   "getFilename",
                                                                   "()Ljava/lang/String;");

QAndroidJniObject status = QAndroidJniObject::callStaticObjectMethod("org/qcolocrypt/AESCrypt",
                                                                   "getStatus",
                                                                   "()Ljava/lang/String;");

這是其中三個函數的Java代碼:

不工作的一個:

public static void AESCryptInit (String passwd, String datafile){

    // Initializing variables.
    rawdata = null;
    status = "";
    fileName = datafile;

    Log.i("[QCOLOCRYPT]","The filename is " + datafile);

    // Transforming the passwd to 16 bytes.
    try {
        MessageDigest digester = MessageDigest.getInstance("MD5");
        InputStream in = new ByteArrayInputStream(Charset.forName(encoding).encode(passwd).array());
        byte[] buffer = new byte[NCHARS];
        int byteCount;
        while ((byteCount = in.read(buffer)) > 0) {
            digester.update(buffer, 0, byteCount);
        }
        keyBytes = digester.digest();
    }
    catch(Exception e){
        status = "Error in key generation: " + e.toString();
    }

    // Initilizing the crypto engine
    try {
        cipher = Cipher.getInstance(algorithm);
    }
    catch(Exception e){
        status = "Error in intialization: " + e.toString();
    }
    secretKeySpec = new SecretKeySpec(keyBytes, "AES");
    ivParameterSpec = new IvParameterSpec(keyBytes);

}

還有兩個有效

// Getting status
public static String getStatus(){return status;}

public static String getFilename() {
   Log.i("[QCOLOCRYPT]","Getting the file name");
   return "The Filename is: " + fileName;
}

由於正在打印日志消息以及其他兩個函數的返回值,因此未打印其調試消息,因此未調用非工作函數。 Logcat似乎沒有顯示任何錯誤,所以我很茫然。 我說錯了嗎?

好的,所以這不是一個答案。 這更多是一種解決方法,我可以使用該函數,但是唯一的方法是返回String。 我已經嘗試過使用(Arguments)I; 作為簽名,但我遇到了同樣的問題。 我修改了Java函數以返回狀態字符串,更改了簽名以反映這一點,並且一切正常。 雖然很奇怪。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM