The operator + is undefined for the argument type (s) CharSequence, int

0

I am trying to concatenate a text in% with% with% with%, but java warns that it is not possible to do this by saying:

  

The operator + is undefined for the argument type (s) CharSequence, int

I have already tried to remove the casting from CharSequence , in addition to "giving" a int at all, but the application does not start when I do this.

package br.edu.ifgoiano.cadastrodeprodutos;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

public class Cadastrar extends Activity {
    Principal principal = new Principal();
/*  private int cont = 0;
    private int varAux;*/
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cadastrar);
    }

    public void tirarFoto(View view) {
        Intent tiraFoto = new Intent("android.media.action.IMAGE_CAPTURE");
        startActivityForResult(tiraFoto, 0);
    }
    **public void qntProd() {
        int cont = 0;
        if (cont == 0) {
            principal.quanti.setText((CharSequence) "Você não possui produtos cadastrados.");
        } else {
            principal.quanti.setText("Você possui " + cont +" produtos cadastrados.");
        }**
    }
    /*public int qntProdCadastrados() {
            if(cont == 0) {
                varAux =  cont;
            }else if(cont > 0){
                varAux = cont;
            }
        cont++;
        return varAux;
    }*/
    public void enviar(View view) {
        Toast.makeText(this, "O cadastro foi realizado com sucesso", Toast.LENGTH_LONG).show(); 
        Intent telaInicial = new Intent(this, Principal.class);
        startActivity(telaInicial);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data){
        if(data != null) {
            Bundle bundle = data.getExtras();
            if(bundle != null) {
                Bitmap img = (Bitmap) bundle.get("data");
                ImageView imagem = (ImageView) findViewById(R.id.imagem);
                imagem.setImageBitmap(img);
            }
        }
    }
}
    
asked by anonymous 09.07.2018 / 19:58

1 answer

2

I believe this is only to work since String is subtype of CharSequence :

principal.quanti.setText("Você possui " + cont + " produtos cadastrados.")

If you really need to, you can do:

principal.quanti.setText((CharSequence)("Você possui " + cont + " produtos cadastrados."))
    
09.07.2018 / 20:31