【问题标题】:Integer.parseInt("0x1F60A") ends up with NumberformatExceptionInteger.parseInt("0x1F60A") 以 NumberformatException 结束
【发布时间】:2017-01-26 11:53:38
【问题描述】:

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

起初,我尝试通过 tv.setText(beforeEmo + getEmijoByUnicode((int)emoKind)); 来转换变量,但 Android Studio 提示:“无法将 'java.lang.String' 转换为 int”...

getEmijoByUnicode 方法是:

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

所以我尝试了这个:

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

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

【问题讨论】:

标签: java android emoji numberformatexception


【解决方案1】:

试试

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

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-11
    • 2015-07-16
    • 2018-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-25
    • 1970-01-01
    相关资源
    最近更新 更多