fsadfasdf
fsadfasdf

Reputation: 11

int cannot be converted to java.lang.String

int i = 0;
String[] b = new String[]{releaseId, i});

causes an int cannot be converted to java.lang.String

From what I know java does implicit String conversion (in case of non-primitives a call to toString()) ?

So what is wrong here?

Is there something different about Java for Android?!

Upvotes: 0

Views: 12974

Answers (3)

Brian
Brian

Reputation: 53

There are 2 "good" ways to convert an integer to a String. Integer.toString(i) or String.valueOf(i).

It is possible to do something like this String s = "" + i; but that is considered a bad smell.

Upvotes: 0

Aleksandr Podkutin
Aleksandr Podkutin

Reputation: 2580

Yes,

int cannot be converted to java.lang.String

Java doing implicit String conversion for Objects, not for primitive types.

You need to use Integer or String.valueOf(i).

Upvotes: 1

Blackbelt
Blackbelt

Reputation: 157487

From what I know java does implicit String conversion (in case of non-primitives a call to toString()) ? So what is wrong here?

That's true for objects. int is a primitive type not an object.

Use String.valueOf(i) to retrieve the String representation of i

Upvotes: 8

Related Questions