Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I try to get the emoji code inside a long string from database, in this format: 0x1F60A ... So I can access the code but it will be a String.

At first, I tried to cast the variable by doing tv.setText(beforeEmo + getEmijoByUnicode((int)emoKind)); but Android Studio hints: "cannot cast 'java.lang.String' to int"...

The getEmijoByUnicode method is:

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

So I tried this one:

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

but it crashes with NumberFormatError. Is there any way to make the emoji appear in my text?

like image 869
M.Hadi Avatar asked Dec 28 '25 07:12

M.Hadi


1 Answers

Try

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

or

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

to convert the string to int or long. So you have to get rid of the "0x", like this

getEmijoByUnicode(Integer.parseInt(emoKind.substring(2), 16));
like image 55
gus27 Avatar answered Dec 30 '25 19:12

gus27