0
public static final String Create_Database2= "CREATE TABLE " + Table_Name2 + "("
                + play20 + "INTEGER PRIMARY KEY, "
                + play1 + " LONG, " 
                + play2 + " LONG, " 
                + play3 + " INTEGER, " 
                + play4 + " INTEGER, " 
                + play5 + " LONG, " 
                + play6 + " TEXT, " 
                + play7 + " TEXT, " 
                + play8 + " TEXT, " 
                + play9 + " TEXT, " 
                + play10 + " TEXT, " 
                + play11 + " INTEGER, " 
                + play12 + " INTEGER, " 
                + play13 + " INTEGER, " 
                + play14 + " INTEGER, " 
                + play15 + " INTEGER, " 
                + play16 + " INTEGER, " 
                + play17 + " TEXT, " 
                + play18 + " INTEGER, " 
                + play19 + " TEXT"
                + ") ";

i am creating a table by using above method? and i am inserting the values in this table by using this method;

 public void fetchplaylist() throws IOException
          {
                this.open();                  
                ContentValues values2 = new ContentValues();
                String csvFilename2 = "/mnt/sdcard/playlist.csv";
                CSVReader csvReader2 = new CSVReader(new FileReader(csvFilename2));
            String Row[] = null;
                while((Row = csvReader2.readNext()) != null) {
                       st1=Row[0];
                       st2=Row[1];
                       st3=Row[2];
                       st4=Row[3];
                       st5=Row[4];
                       st6=Row[5];
                       st7=Row[6];
                       st8=Row[7];
                       st9=Row[8];
                       st10=Row[9];
                       st11=Row[10];
                       st12=Row[11];
                       st13=Row[12];
                       st14=Row[13];
                       st15=Row[15];
                       st16=Row[16];
                       st17=Row[17];
                       st18=Row[18];
                       st19=Row[19];
                       values2.put(DatabaseHandler.play1,st1);
                       values2.put(DatabaseHandler.play2,st2);
                       values2.put(DatabaseHandler.play3,st3);
                       values2.put(DatabaseHandler.play4,st4);
                       values2.put(DatabaseHandler.play5,st5);
                       values2.put(DatabaseHandler.play6,st6);
                       values2.put(DatabaseHandler.play7,st7);
                       values2.put(DatabaseHandler.play8,st8);
                       values2.put(DatabaseHandler.play9,st9);
                       values2.put(DatabaseHandler.play10,st10);
                       values2.put(DatabaseHandler.play11,st11);
                       values2.put(DatabaseHandler.play12,st12);
                       values2.put(DatabaseHandler.play13,st13);
                       values2.put(DatabaseHandler.play14,st14);
                       values2.put(DatabaseHandler.play15,st15);
                       values2.put(DatabaseHandler.play16,st16);
                       values2.put(DatabaseHandler.play17,st17);
                       values2.put(DatabaseHandler.play18,st18);
                       values2.put(DatabaseHandler.play19,st19);
                   database.insert(DatabaseHandler.Table_Name2, null, values2); }

but i am setting sqlite error code 19 constraints fail in my logcat what am i doing worng here?i am unable to understand this please will someone help me understand this

2 Answers 2

4

You have a missing space before

"INTEGER PRIMARY KEY

replace it with:

" INTEGER PRIMARY KEY
Sign up to request clarification or add additional context in comments.

4 Comments

after making the changes as you mentioned now i am getting this error
java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0, any help please its important for me
The error indicates that you are accessing an array or collection that has no elements. Please point out the line where the error occurs.
@PramodYadav: Don't know how the CSVReader works, but the cause of the excepetion might be that you check your array for null but you don't check the size of the array before accessing its elements.
0

you need to clear you ContentValues, or put this line

ContentValues values2 = new ContentValues();

inside while loop and give space before " INTEGER PRIMARY KEY"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.