Sto avendo qualche problema serio con questo codice, da svg-android:Android 6.0 (Marshmallow) ad eccezione di inizializzazione statico sul getDeclaredField()
public class ParserHelper {
private static final Field STRING_CHARS;
static {
try {
STRING_CHARS = String.class.getDeclaredField("value"); //<-- exception here
STRING_CHARS.setAccessible(true);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private final char[] s;
private final int n;
private char current;
public int pos;
public ParserHelper(String str, int pos) {
try {
this.s = (char[]) STRING_CHARS.get(str);
} catch (Exception e) {
throw new RuntimeException(e);
}
this.pos = pos;
n = s.length;
current = s[pos];
}
il STRING_CHARS = String.class.getDeclaredField("value");
getta l'excpetion
10-09 10: 25: 58.240: E/AndroidRuntime (3430): causato da: java.lang.RuntimeException: java.lang.NoSuchFieldException: nessun campo valore nella classe Ljava/lang/String; (Dichiarazione di 'java.lang.String' appare in /system/framework/core-libart.jar)
non posso continuare il lavoro. Solo su Android 6.0 Marshmallow. Qualche idea?
risolto: Ora, non ho risolto il problema di inizializzazione statico ma ho cambiato il char[] s
di inizializzazione:
public class ParserHelper {
// private static final Field STRING_CHARS;
// static {
// try {
// STRING_CHARS = String.class.getDeclaredField("value");
// STRING_CHARS.setAccessible(true);
// } catch (Exception e) {
// throw new RuntimeException(e);
// }
// }
private final char[] s;
private final int n;
private char current;
public int pos;
public ParserHelper(String str, int pos) {
try {
s = new char[str.length()];
str.getChars(0, str.length(), this.s, 0); //<-- here
} catch (Exception e) {
throw new RuntimeException(e);
}
this.pos = pos;
n = s.length;
current = s[pos];
}
Non è necessario utilizzare un'istanza String per eseguire la riflessione? non un esperto su di esso. – Nanoc
@Nanoc me neanche ... –
Quindi prova questo e dimmi "new String (" Hello "). Class.getDeclaredField (" value ");" – Nanoc