1

i have create a table in sqlite that giving me java.lang.ArrayIndexOutOfBoundsException here is code :

db.execSQL("CREATE TABLE "+scoreboardTable+" ("+scoreboard_id+ " INTEGER PRIMARY KEY NOT NULL,"+" FOREIGN KEY ( "+player_fk+ ") REFERENCES "+playerTable+" ("+playerid+ "), "
        +"FOREIGN KEY ( "+ Template_fk+ ") REFERENCES " +TemplateTable+" ("+ templateid+ "),"+ total_flick+"int"+surprise_success+"varchar"+surprise_failure+"varchar)");
    }

and

public void Insert_scoreboard(String[] str) 
    {
        try
        {
        SQLiteDatabase DB= this.getWritableDatabase();
        ContentValues cv=new ContentValues();

        cv.put("scoreboard_id", str[0]);
        cv.put("player_fk", str[1]);
        cv.put("Template_fk", str[2]);
        cv.put("total_flick", str[3]);
        cv.put("surprise_success", str[4]);
        cv.put("surprise_failure", str[5]);


        DB.insert( scoreboardTable , "scoreboard", cv);
        DB.close();
        }
        catch(Exception ex)
        {
            ex.toString();
        }

where im doing wrong .

1
  • Unrelated to your issue, but another possibility for receiving this is if you're using a PreparedStatement and you've put single quotes around your ? parameters. It will treat them as a string literal and ignore your parameter. Question-mark parameter should not be quoted. Commented Feb 11, 2020 at 18:35

1 Answer 1

2

You have error in Create Table Syntax ( you forgot comma , at some places ) update your code with following code,

db.execSQL( "CREATE TABLE " + scoreboardTable + " (" + scoreboard_id + " INTEGER PRIMARY KEY NOT NULL," + " FOREIGN KEY ( "+player_fk+ ") REFERENCES " + playerTable + " (" + playerid + "), " + "FOREIGN KEY ( " + Template_fk + ") REFERENCES " + TemplateTable + " (" + templateid + ")," + total_flick + "int, " + surprise_success + "varchar, " + surprise_failure + "varchar)" );
    }
Sign up to request clarification or add additional context in comments.

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.