Why this error: required java.lang.string found int (Android Studio)?

2

I have a table in sqlite with an integer field called Tipo , it happens that according to the type number certain options will be shown to the user, so I made a switch but it marks the error in the number of case of switch :

  

"Incompatible types, required java.lang.String, found int"

and I do not understand why.

private conexion con;
Context context;
SQLiteDatabase bd;

//inicializar
con=new conexion(context,"bd_SQLITE",null,1);
bd= con.getWritableDatabase();

//metodo para consultar
Cursor c = bd.rawQuery("SELECT * FROM Tablasql", null);

if(c!=null)
 {
 switch (Tablasql.Tipo){
 case 1: 
 nota =  "Persona1: "+c.getString(c.getColumnIndex("Nombre"));
 nota =  "Telefono: +c.getString(c.getColumnIndex("Telefono"));
    break; 
    
 case 2: 
 nota =  "Persona2: "+c.getString(c.getColumnIndex("Nombre"));
 nota =  "Telefono: +c.getString(c.getColumnIndex("Telefono"));
    break; 
}   
c.close();
bd.close();

I clarify that in the switch where I put Tablasql.Type is:

public class Inicio_Detalle_Caso {
    public static final String Tablasql="Tablasql";
    public static final String id="id";
    public static final String Telefono="Telefono";
    public static final String Nombre="Nombre";
     public static final String Tipo="Tipo";
    

    public static final String creart="create table Tablasql"+Tablasql+"("+id+" integer, "+Telefono+" text, "+
            Nombre+" text, "+Tipo+" integer)";
}
    
asked by Geek 20.08.2018 в 19:09
source

1 answer

0

You are getting Tipo incorrectly, you should bring it using your cursor:

c.getInt("Tipo")

Finally your switch would be like this:

if(c!=null)
 {
 switch (c.getInt("Tipo")){
 case 1: 
 nota =  "Persona1: "+c.getString(c.getColumnIndex("Nombre"));
 nota =  "Telefono: "+c.getString(c.getColumnIndex("Telefono"));
    break; 

 case 2: 
 nota =  "Persona2: "+c.getString(c.getColumnIndex("Nombre"));
 nota =  "Telefono: "+c.getString(c.getColumnIndex("Telefono"));
    break; 
}   
    
answered by 20.08.2018 / 19:57
source