Thursday 15 July 2010

java - Cannot insert values into SQLite database in android -


I have three classes I is an activity that sends the text of EditTexts to another class:

  string [] comments = new string [] {number.getText (). ToString (), ship_name.gate text () ToString (), ...} / 20 such values ​​commented = datastart.Create comment (comment);   

This class handles Comments:

  private String [] allColumns = {MySQLiteHelper.COLUMN_ID, MySQLiteHelper.COLUMN_IMO_NUMBER, MySQLiteHelper.COLUMN_VESSEL_NAME,. ..} // 21 make such value public VesproModel comment (string comment []) {long insertId = 0; Int i = 1, j = 0; Cursor cursor = null; Material values ​​= new material value (); Values.put (allColumns [0], insertId); {Values.put (all columns [i], comment [j] for I & lt; allColumns.length & amp; amp; amp; & amp; j & lt; comment length; i ++, j ++) ); InsertId = database.insert (MySQLiteHelper.TABLE_TPCS_VESSEL, zero, value); Cursor = database.query (MySQLiteHelper.TABLE_TPCS_VESSEL, all columns, MySQLiteHelper.COLUMN_ID + "=" + insert, empty, empty, empty, zero); } Cursor.movetofst (); VesproModel newcomment = cursor output (cursor); Cursor.close (); Return new comment; } Private VesproModel cursorToComment (cursor cursor) {VesproModel Comment = New VesproModel (); Log D. ("Cursor changes comment", "before cursor tutorial"); If (cursor! = Null & cursor. Posterior tofest ()) {log d. ("Post-cursor comment", "comment inside cursor"); Comment.setId (cursor.getLong (0)); Comment.setImo_number (cursor.getString (1)); Comment.setVessel_name (cursor.getString (2)); Comment.setVessel_type (cursor.getString (3)); ... ... comment.setNo_engines (cursor.getINt (20)); } And Log D. ("Cursor Tutorial", "Zero Evaluation"); Remarks of return; }   

VesproModel includes variables and their gates and setters. MySQLiteHelper class SQLiteOpenHelper class exxtends which handles the query to create a table called TPC_VESSEL error message displays Logkt:

  06-21 10: 45: 03.826: E / SQLite database (24135): error inserting _id = 0 imo_number = YB 06-21 10: 45: 03.826: e / SQLiteDatabase (24,135): android.database.sqlite.SQLiteConstraintException: the TPCS_VESSEl.vessel_name can not be NULL (code 19) 06-2l October 45 : 03,826: e / SQLiteDatabase (24,135): .nativeExecuteForLastInsertedRowId (Native method android.database.sqlite.SQLiteConnection) 06-21 October: 45: 03,826 e / SQLiteDatabase (24,135): to android.database. Sqlite.SQLiteConnection.executeForLastInsertedRowId (SQLiteConn Ection.java:775) 06-21 October: 45: 03.826: E / SQLiteDatabase (24,135): 06.10 october: 45: 03 at com.example.pcs.VesproDataSource.createComment (VesproDataSource.java:60). 846: e / SQLiteDatabase (24,135): insert error _ id = 0 imo_number = YB vessel_name = ego 06 -21 10: 45: 03,846 e / SQLiteDatabase (24,135): android.database.sqlite.SQLiteConstraintException: TPCS_VESSEl. vessel_type NULL (code 19) may not be October 06-2l: 45: 03,846 e / SQLiteDatabase (24,135): aSource.createComment on Com.example.pcs.VesproDat (VesproDataSource.java:60) 06-21 Aktubr : 45: 03.856: E / SQLiteDatabase (24,135): Entering the error _ id = 0 vessel_type = container imo_number = y b-vessel_name = ego   

1 Edit : Create table command in the MySQLiteHelper class:

  database. ExecSQL ("Table" + "TABLE_TPCS_VESSEL +" ("+ COLUMN_ID +" integer primary key autoincrement, "+ COLUMN_IMO_NUMBER +" text is not zero, "+ COLUMN_VESSEL_NAME +" text is meaningless, the text "+ COLUMN_VESSEL_TYPE +" is not zero, "+ COLUMN_SR_CERTIFICATE_NO +" The text is not empty, "+ ... .... COLUMN_NO_ENGINES +" is not an integer faucet); ";    

The logkets say all this

TPCS_VESSEL vessel_name may not be blank. It seems that you have given it to null < / Code> declared when not created, then better Set a default value to form. Or take when entering a value in the variable

No comments:

Post a Comment