Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 不相容类型;需要和找到。但找到的是必需的类型_Java_Android - Fatal编程技术网

Java 不相容类型;需要和找到。但找到的是必需的类型

Java 不相容类型;需要和找到。但找到的是必需的类型,java,android,Java,Android,我收到错误“不兼容的类型。必需:字节[]。找到:java.lang.string 我已经尝试了来自的解决方案,该解决方案声明我必须初始化类型。我初始化了字节[],但仍然收到该错误 public static byte[] hash(char[] password, byte[] salt) { PBEKeySpec spec = new PBEKeySpec(password, salt, ITERATIONS, KEY_LENGTH); Arrays.fill(password

我收到错误“不兼容的类型。必需:字节[]。找到:java.lang.string

我已经尝试了来自的解决方案,该解决方案声明我必须初始化类型。我初始化了字节[],但仍然收到该错误

public static byte[] hash(char[] password, byte[] salt) {
    PBEKeySpec spec = new PBEKeySpec(password, salt, ITERATIONS, KEY_LENGTH);
    Arrays.fill(password, Character.MIN_VALUE);
    try {
        SecretKeyFactory skf = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
        byte [] hashedPass =  skf.generateSecret(spec).getEncoded();
        return toHex(hashedPass);
    } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
        throw new AssertionError("Error while hashing a password: " + e.getMessage(), e);
    } finally {
        spec.clearPassword();
    }
}

public static String toHex(byte[] Array){
    BigInteger bi = new BigInteger(1, Array);
    String hex = bi.toString(16);
    int paddingLength = (Array.length *2) - hex.length();
    if (paddingLength > 0){
        return String.format("%0" + paddingLength +"d", 0) + hex;
    } else {
        return hex;
    }
}
我在第7行得到错误:

return toHex(hashedPass);
方法
hash(char[]password,byte[]salt)
应返回
byte[]
return-toHex(hashedPass)
返回不兼容的字符串

将方法
的返回类型更改为hex(hashedPass)
并返回
字节[]
或 变,

return toHex(hashedPass);
return toHex(hashedPass).getBytes();