私はsvg-androidから、このコードでいくつかの深刻な問題を抱えている:のAndroid 6.0(マシュマロ)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];
}
STRING_CHARS = String.class.getDeclaredField("value");
はexcpetionをスロー
10月9日10:25:58.240:E/AndroidRuntime(3430):原因: java.lang.RuntimeException:java.lang.NoSuchFieldException:Noフィールド クラスLjava/lang/Stringの値。
私が仕事を継続することはできません( 'はjava.lang.String型' の宣言は/system/framework/core-libart.jarに表示されます)。 Android 6.0でのみマシュマロ。何か案が?
は解決: は今、私は静的な初期化の問題を解決しませんでしたが、私はchar[] s
初期設定を変更:文字の配列を保持しているvalue
呼ばString
のプライベートフィールドだったよう
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];
}
反射を実行するためにStringインスタンスを使用する必要はありませんか?それに関する専門家ではありません。 – Nanoc
@Nanoc私も... –
これを代わりに試してみて、 "新しい文字列(" Hello ")を教えてください。class.getDeclaredField(" value ");" – Nanoc