0

this is a project to shcool and im quiet new to this progamming world and i was trying to put some information into the textviews but this error don t let me "expected android.widget.textview but found java.lang.string" i dont know what more to do

//this the xml

LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent">


        <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
            android:id="@+id/texto_1"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/texto_2"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/texto_3"/>





    </LinearLayout>

this is the java

 SQLiteDatabase db;
    Cursor c;
    String nota;

    SimpleCursorAdapter adapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notasver);
        DB mDbHelper = new DB(this);
        db = mDbHelper.getReadableDatabase();
        Intent i = getIntent();
        Bundle dados = i.getExtras();
       nota = dados.getString(Contrato.Notas._ID, null);
        mostrar();

    }

    public void mostrar()
    {TextView nome = (TextView) findViewById(R.id.texto_1);
        TextView descricao = (TextView) findViewById(R.id.texto_2);
        TextView data_criacao = (TextView) findViewById(R.id.texto_3);
      c = db.query(false, Contrato.Notas.TABLE_NAME, Contrato.Notas.PROJECTION, Contrato.Notas.COLUMN_ID_USER + "= ? ", new String[] {nota}, null,null,null,null);
           nome = c.getString(c.getColumnIndex(Contrato.Notas.COLUMN_NOME));//error here
            descricao = c.getString(c.getColumnIndex(Contrato.Notas.COLUMN_NOME));//error here
            data_criacao = c.getString(c.getColumnIndex(Contrato.Notas.COLUMN_NOME));//error here


    }
R Monkey
  • 131
  • 1
  • 10
  • You need to use the `TextView#setText()` method to set a `TextView`'s text. You can't assign a `String` to a `TextView` variable. – Mike M. Oct 20 '17 at 02:22

1 Answers1

0

Try to do like this .

public void mostrar() {
    TextView nome = (TextView) findViewById(R.id.texto_1);
    TextView descricao = (TextView) findViewById(R.id.texto_2);
    TextView data_criacao = (TextView) findViewById(R.id.texto_3);
    c = db.query(false, Contrato.Notas.TABLE_NAME, Contrato.Notas.PROJECTION, Contrato.Notas.COLUMN_ID_USER + "= ? ", new String[]{nota}, null, null, null, null);
    // edited here ,try to change nome to nomeString
    if (null == c) {
        return;
    }
    if(c.moveToFirst()){
        String nomeString = c.getString(c.getColumnIndex(Contrato.Notas.COLUMN_NOME));
        String descricaoString = c.getString(c.getColumnIndex(Contrato.Notas.COLUMN_NOME));
        String data_criacaoString = c.getString(c.getColumnIndex(Contrato.Notas.COLUMN_NOME));
        // then set to your textview
        nome.setText(nomeString);
        descricao.setText(descricaoString);
        data_criacao.setText(data_criacaoString);
    }
}
KeLiuyue
  • 8,149
  • 4
  • 25
  • 42