String.format() with error

Asked

Viewed 184 times

0

I need to format the following string with the respective parameter, but this generating the following error:

Caused by: java.util.Illegalformatconversionexception: %d can’t format java.lang.String Arguments

private static final String URL_HOST = "http://xxxx.com/";    
private static final String URL_VERIFICA_ATUALIZACAO = "aaaa/%d";
String url = String.format(URL_HOST + URL_VERIFICA_ATUALIZACAO, ultimaConfiguracao.getUltima_atualizacao()); //retorna um Long (valor zero)

Estate:

@DatabaseField(dataType = DataType.LONG, canBeNull = false, defaultValue = "0")
private long ultima_atualizacao;

public long getUltima_atualizacao() {
        return ultima_atualizacao;
    }

public void setUltima_atualizacao(long ultima_atualizacao) {
        this.ultima_atualizacao = ultima_atualizacao;
    }
  • 1

    Sure the error is on this msm line? I did a test here and can’t imagine what might be causing the error. Try making a Minimum, Complete and Verifiable Example

  • @Math is doing this within an asynchronous method, which until now was generating other errors, but the last one is this... (I’m inexperienced on Android), I created the entire code of a necessary class and now I’m testing, I do not believe it is a bug Android Studio accuse the error in the wrong line...

  • Friend, does the error persist? If yes, I am reproducing the error here, and it is returning normal when I use a Long, or Int, but the mistake is right when it is String... What this part defines defaultValue = "0" in the annotation above the property?

  • @Gustavocinque he says that the default value is zero, I managed to solve the problem but I did not understand why it occurs, I did the test and I switched for string, but it was strange because in fact it is a Long... will understand?

  • Um... for me when I use String is when it goes wrong. I thought that defaultValue = "0" defines the value of Long in the database as Character or something, but I believe that.

  • It just arrow the default value to long zero.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.