期待android.widget.textview但找到了java.lang.string

时间:2017-10-20 02:18:26

标签: java android

这是一个shcool的项目,我对这个编程世界很新,我试图将一些信息放到textviews中,但是这个错误让我不能预见到android.widget.textview但是找到了java.lang .string"我不知道还能做什么

//这是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>

这是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


    }

1 个答案:

答案 0 :(得分:0)

尝试这样做。

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);
    }
}