Question

This is my code:

 public void idoKiiras(){
    String idostring = new String();
    idostring.valueOf(System.currentTimeMillis());
    System.out.print(idostring);
    ido.setText(idostring);
}

What i get in the string is nothing, it's empty. Any solution?

Was it helpful?

Solution

String.valueOf() is a static method that returns a String value. Use it like so

String idostring = String.valueOf(System.currentTimeMillis());
System.out.print(idostring);
ido.setText(idostring);

Previously, you were using the valueOf method but not doing anything with its return value.

idostring.valueOf(System.currentTimeMillis());

Remember that String objects are immutable. No String method will ever change the String internally, it will always return a new String object.

OTHER TIPS

@Sotirios already answered this, beautifully, but, I just want to give you a little tip to help anyone that has this problem.

Set the idostring to a silly value at the initialisation phase that way you can see whether it is being changed from the various methods.

E.g

String idostring = "THIS_SHOULD_CHANGE";

That way, when you get to setting the text of ido, you won't have a blank label/button/textview.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top