Integer.parseInt("0x1F60A") 以 NumberformatException 结尾

Integer.parseInt("0x1F60A") ends up with NumberformatException

我尝试从数据库中获取一个长字符串中的表情符号代码,格式为:0x1F60A ...所以我可以访问该代码,但它将是 字符串.

起初,我尝试通过 tv.setText(beforeEmo + getEmijoByUnicode((int)emoKind)); 来转换变量,但 Android Studio 提示:"cannot cast 'java.lang.String' to int"...

getEmijoByUnicode方法是:

public String getEmijoByUnicode(int unicode) {
    return new String(Character.toChars(unicode));
}

所以我尝试了这个:

tv.setText(beforeEmo + getEmijoByUnicode(Integer.parseInt(emoKind)));

但它因 NumberFormatError 而崩溃。有什么方法可以让表情符号出现在我的文本中吗?

尝试

Integer.parseInt("1F60A", 16);

Long.parseLong("1F60A", 16);

将字符串转换为 int 或 long。所以你必须像这样去掉“0x”

getEmijoByUnicode(Integer.parseInt(emoKind.substring(2), 16));