android - using Object... in codenameone -
i'm using codenameone develop application in mobile. want create method show error message on screen. got error:
this code
public class common {
public static boolean checknullorempty(string value){ return !(value != null && !value.equals("")); } public static void showmessage(string title,string msgid, object... params){ string result = string.format(msgid, params); dialog.show(title, result, "ok", "cancel"); } }
and way call method:
common.showmessage("error", "item %s ; item %s","01","02");
this error message:
error: cannot find symbol string result = string.format(msgid, params);
symbol: method format(string,object[]) location: class string
can me? lot.
string.format isn't supported codename 1 subset of java api. should able use stringutil.replaceall etc. replace entries e.g. this:
common.showmessage("error", "item {0} ; item {1}","01","02"); you should able this:
string result = msgid; for(int iter = 0 ; iter < params.length ; iter++) { result = stringutil.replaceall(result, "{" + iter + "}", params[iter]); }
Comments
Post a Comment