sqlite android错误保存咨询

时间:2016-03-11 04:06:12

标签: android sqlite memory input

我正在编写应用程序时遇到问题,在使用sqlite编写应用程序并且crud工作正常但现在我有一个错误时,应用程序保存了一个内存空间o其他东西但是在编辑文本中没有单词类型继承人代码

heres the result and the input menu

sqlite数据访问:

public class Acceso_Datos  extends SQLiteOpenHelper {

public Acceso_Datos(Context ctx){
    super(ctx, "kkk", null, 1); 
}
@Override
public void onCreate(SQLiteDatabase db){

    String  query = "CREATE TABLE persona (" +
            _ID+" INTEGER PRIMARY KEY AUTOINCREMENT," +
            "rut TEXT,"+
            "nombre TEXT,"+
            "apellido TEXT,"+
            "seccion TEXT)";

db.execSQL(query);
}
@Override
public void onUpgrade(SQLiteDatabase db, int version_ant, int version_nue){
onCreate(db);
db.execSQL("DROP TABLE EXISTS persona");

 }



//Método para agregar datos
public void insertar(String rut,String nom, String ap,String sec){
abrir();
ContentValues valores  = new ContentValues();
valores.put("rut", rut);
valores.put("nombre", nom);
valores.put("apellido", ap);
valores.put("seccion", sec);
this.getWritableDatabase().insert("persona", null, valores);        
cerrar();
}

public String leer(){
String resultado="";

String filas[] = {_ID, "rut","nombre", "apellido","seccion"};
Cursor c = this.getReadableDatabase().query("persona", filas,null, null,        null, null, null);
int id,rut, nom, ape, sec;
id= c.getColumnIndex(_ID);
rut= c.getColumnIndex("rut");
nom= c.getColumnIndex("nombre");
ape= c.getColumnIndex("apellido");
sec= c.getColumnIndex("seccion");

while(c.moveToNext())
{
    resultado += 
            c.getString(id) +"  "+ 
            c.getString(rut)+"  "+
            c.getString(nom)+"  "+
            c.getString(ape)+"  "+
            c.getString(sec)+"\n";          
}

return resultado;

}

主:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.asistencia.MainActivity" >

<EditText
    android:id="@+id/v1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="21dp"
    android:ems="10" >

    <requestFocus />
</EditText>

<EditText
    android:id="@+id/v2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="46dp"
    android:ems="10"
    android:inputType="textPersonName" />

<EditText
    android:id="@+id/v3"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="textPersonName" />

<EditText
    android:id="@+id/v4"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="172dp"
        android:layout_marginLeft="28dp"
        android:onClick="ok"
        android:text="Button" />

    <Button
        android:id="@+id/ver"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="32dp"
        android:onClick="ver"
        android:text="Button" />

</LinearLayout>

java main:

package com.example.asistencia;



public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}
public void ok(View v){
    Acceso_Datos a=new Acceso_Datos(this);
    EditText v1=(EditText)findViewById(R.id.v1);
    EditText v2=(EditText)findViewById(R.id.v2);
    EditText v3=(EditText)findViewById(R.id.v3);
    EditText v4=(EditText)findViewById(R.id.v4);
    a.insertar(
            v1.toString(),
            v2.toString(), 
            v3.toString(), 
            v4.toString());

}
public void ver(View v){
    Intent m=new Intent(MainActivity.this,Ver.class);
    startActivity(m);
}

}

和节目活动:

Acceso_Datos a=new Acceso_Datos(this);
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_ver);

    TextView tv=(TextView)findViewById(R.id.resultado);
    tv.setText(a.leer().toString());
    }

1 个答案:

答案 0 :(得分:1)

替换

a.insertar(
        v1.toString(),
        v2.toString(), 
        v3.toString(), 
        v4.toString());

String text_v1 = v1.getText.toString();
String text_v2 = v2.getText.toString();
String text_v3 = v3.getText.toString();
String text_v4 = v4.getText.toString();
a.insetar(text_v1,text_v2,text_v3,text_4);

试试吧!