所以我正在构建这个Android模拟游戏,我有一些SQL和数组问题。
在尝试从数组中的随机位置放置一些值时,我在这些行上得到了数组越界错误:
int max = 10;
int min = 0;
Random r = new Random();
int num = r.nextInt(max-min) + min;
if (west_teams[num].equals(teams[0]) ||
west_teams[num].equals(teams[1]) ||
west_teams[num].equals(teams[2]) ||
west_teams[num].equals(teams[3]) ||
west_teams[num].equals(teams[4]) ||
west_teams[num].equals(teams[5]) ||
west_teams[num].equals(teams[6]) ||
west_teams[num].equals(teams[7])
)
在SQLite问题中,我在这些行上得到Java空指针异常错误:
ContentValues cv = new ContentValues();
cv.put(TEAM, team);
cv.put(LOCATION, Location);
cv.put(PLAYER, Player);
cv.put(CRANGE, cRange);
cv.put(MRANGE, mRange);
cv.put(TRANGE, tRange);
cv.put(FREETHROW, Freethrow);
cv.put(PASS, Pass);
cv.put(DEF_REBOUND, Def_rebound);
cv.put(OFF_REBOUND, Off_rebound);
cv.put(BLOCK, Block);
cv.put(STEAL, Steal);
cv.put(STAMINA, Stamina);
return ourDatabase.insert(PLAYERS_TABLE, null, cv);
这是我的完整代码:
package ent.com;
import java.util.Random;
import android.content.Context;
public class RandPlayers {
protected Context context;
public void fetch_players(String location, String savename){
this.context = context;
String[] first_names = new String[] {"John", "Jonathan", "James", "Drew", "Tim", "Tony", "Anthony", "Andrew", "Brandon", "Michael", "Mike", "Devin", "Marcus", "George", "Noah", "Martin", "Kevin", "Quentin", "Boris", "Stepehn"};
String[] last_names = new String[] {"Parker", "Robinson", "Jackson", "Charles", "Powell", "Wilkerson", "Mitchell", "Russel", "Flint", "Griffin", "Simpson", "Springfield", "Booker", "Wilks", "Flanders", "Levingston", "Fernandez", "Rodriguez", "Evans", "Smith"};
String[] west_teams = new String[] {"Seattle Ice", "Las Vegas Dragons", "Salt Lake Vampires", "Vancouver Wildfire", "Olympia Peninsulas", "San Diego Rings", "San Francisco Flyers", "Austin Fortress", "Idaho Eagles"};
String[] east_teams = new String[] {"Jackson Giants", "Tampa Wildbears", "Nashville Monarchs", "Springfield Defenders", "Minneapolis Ballers", "Ottawa Moose", "Columbus Natives", "Cincinnati Lightning", "Baltimore Invaders", "Montreal Fishers"};
String[] teams = new String[] {"","","","","","","","","","","","","","","",""};
String[] players = new String[] {"","","","","","","","","","","","","","","",""};
SetSql PlayerObject = new SetSql(this.context);
int i;
int y;
if(location.equals("w")){
teams[7] = savename;
for(i = 0; i<7; i++){
int max = 10;
int min = 0;
Random r = new Random();
int num =min + r.nextInt(max-min);
if(west_teams[num].equals(teams[0]) ||
west_teams[num].equals(teams[1]) ||
west_teams[num].equals(teams[2]) ||
west_teams[num].equals(teams[3]) ||
west_teams[num].equals(teams[4]) ||
west_teams[num].equals(teams[5]) ||
west_teams[num].equals(teams[6]) ||
west_teams[num].equals(teams[7]))
{
i--;
}
else{
teams[i] = west_teams[num];
}
}
}
else{
for(i = 0; i<8; i++){
int max = 10;
int min = 0;
Random r = new Random();
int num = r.nextInt(max-min) + min;
if(west_teams[num].equals(teams[0]) ||
west_teams[num].equals(teams[1]) ||
west_teams[num].equals(teams[2]) ||
west_teams[num].equals(teams[3]) ||
west_teams[num].equals(teams[4]) ||
west_teams[num].equals(teams[5]) ||
west_teams[num].equals(teams[6]) ||
west_teams[num].equals(teams[7]))
{
i--;
}
else{
teams[i] = west_teams[num];
}
}
}
if(location.equals("e")){
for(y = 8; y<15; y++){
teams[15] = savename;
int max = 10;
int min = 0;
Random r = new Random();
int num = r.nextInt(max-min) + min;
if(east_teams[num].equals(teams[8]) ||
east_teams[num].equals(teams[9]) ||
east_teams[num].equals(teams[10]) ||
east_teams[num].equals(teams[11]) ||
east_teams[num].equals(teams[12]) ||
east_teams[num].equals(teams[13]) ||
east_teams[num].equals(teams[14]) ||
east_teams[num].equals(teams[15]))
{
y--;
}
else{
teams[y] = west_teams[num];
}
}
}
else{
for(y = 8; y<16; y++){
int max = 10;
int min = 0;
Random r = new Random();
int num = r.nextInt(max-min) + min;
if(east_teams[num].equals(teams[8])||east_teams[num].equals(teams[9])||east_teams[num].equals(teams[10])||east_teams[num].equals(teams[11])||east_teams[num].equals(teams[12])||east_teams[num].equals(teams[13])||east_teams[num].equals(teams[14])||east_teams[num].equals(teams[15]))
{
y--;
}
else{
teams[y] = west_teams[num];
}
}
}
for(int w=0; w<16; w++){
int min = 0;
int max = 20;
int smin = 1;
int smax = 21;
Random names = new Random();
int fnum = names.nextInt(max-min) + min;
int snum = names.nextInt(max-min) + min;
players[0] = first_names[fnum] + " " + last_names[snum];
int cRange = names.nextInt(smax-smin)+smin;
int mRange = names.nextInt(smax-smin)+smin;
int tRange = names.nextInt(smax-smin)+smin;
int Freethrow = names.nextInt(smax-smin)+smin;
int Pass = names.nextInt(smax-smin)+smin;
int Def_rebound = names.nextInt(smax-smin)+smin;
int Off_rebound = names.nextInt(smax-smin)+smin;
int Block = names.nextInt(smax-smin)+smin;
int Steal = names.nextInt(smax-smin)+smin;
int Stamina = names.nextInt(smax-smin)+smin;
PlayerObject.createPlayerEntry(teams[0], "w", players[0], cRange, mRange, tRange, Freethrow, Pass, Def_rebound, Off_rebound, Block, Steal, Stamina);
fnum = names.nextInt(max-min) + min;
snum = names.nextInt(max-min) + min;
players[0] = first_names[fnum] + " " + last_names[snum];
cRange = names.nextInt(smax-smin)+smin;
mRange = names.nextInt(smax-smin)+smin;
tRange = names.nextInt(smax-smin)+smin;
Freethrow = names.nextInt(smax-smin)+smin;
Pass = names.nextInt(smax-smin)+smin;
Def_rebound = names.nextInt(smax-smin)+smin;
Off_rebound = names.nextInt(smax-smin)+smin;
Block = names.nextInt(smax-smin)+smin;
Steal = names.nextInt(smax-smin)+smin;
Stamina = names.nextInt(smax-smin)+smin;
PlayerObject.createPlayerEntry(teams[1], "w", players[1], cRange, mRange, tRange, Freethrow, Pass, Def_rebound, Off_rebound, Block, Steal, Stamina);
fnum = names.nextInt(max-min) + min;
snum = names.nextInt(max-min) + min;
players[0] = first_names[fnum] + " " + last_names[snum];
cRange = names.nextInt(smax-smin)+smin;
mRange = names.nextInt(smax-smin)+smin;
tRange = names.nextInt(smax-smin)+smin;
Freethrow = names.nextInt(smax-smin)+smin;
Pass = names.nextInt(smax-smin)+smin;
Def_rebound = names.nextInt(smax-smin)+smin;
Off_rebound = names.nextInt(smax-smin)+smin;
Block = names.nextInt(smax-smin)+smin;
Steal = names.nextInt(smax-smin)+smin;
Stamina = names.nextInt(smax-smin)+smin;
PlayerObject.createPlayerEntry(teams[2], "w", players[2], cRange, mRange, tRange, Freethrow, Pass, Def_rebound, Off_rebound, Block, Steal, Stamina);
fnum = names.nextInt(max-min) + min;
snum = names.nextInt(max-min) + min;
players[0] = first_names[fnum] + " " + last_names[snum];
cRange = names.nextInt(smax-smin)+smin;
mRange = names.nextInt(smax-smin)+smin;
tRange = names.nextInt(smax-smin)+smin;
Freethrow = names.nextInt(smax-smin)+smin;
Pass = names.nextInt(smax-smin)+smin;
Def_rebound = names.nextInt(smax-smin)+smin;
Off_rebound = names.nextInt(smax-smin)+smin;
Block = names.nextInt(smax-smin)+smin;
Steal = names.nextInt(smax-smin)+smin;
Stamina = names.nextInt(smax-smin)+smin;
PlayerObject.createPlayerEntry(teams[3], "w", players[3], cRange, mRange, tRange, Freethrow, Pass, Def_rebound, Off_rebound, Block, Steal, Stamina);
fnum = names.nextInt(max-min) + min;
snum = names.nextInt(max-min) + min;
players[0] = first_names[fnum] + " " + last_names[snum];
cRange = names.nextInt(smax-smin)+smin;
mRange = names.nextInt(smax-smin)+smin;
tRange = names.nextInt(smax-smin)+smin;
Freethrow = names.nextInt(smax-smin)+smin;
Pass = names.nextInt(smax-smin)+smin;
Def_rebound = names.nextInt(smax-smin)+smin;
Off_rebound = names.nextInt(smax-smin)+smin;
Block = names.nextInt(smax-smin)+smin;
Steal = names.nextInt(smax-smin)+smin;
Stamina = names.nextInt(smax-smin)+smin;
PlayerObject.createPlayerEntry(teams[4], "w", players[4], cRange, mRange, tRange, Freethrow, Pass, Def_rebound, Off_rebound, Block, Steal, Stamina);
fnum = names.nextInt(max-min) + min;
snum = names.nextInt(max-min) + min;
players[0] = first_names[fnum] + " " + last_names[snum];
cRange = names.nextInt(smax-smin)+smin;
mRange = names.nextInt(smax-smin)+smin;
tRange = names.nextInt(smax-smin)+smin;
Freethrow = names.nextInt(smax-smin)+smin;
Pass = names.nextInt(smax-smin)+smin;
Def_rebound = names.nextInt(smax-smin)+smin;
Off_rebound = names.nextInt(smax-smin)+smin;
Block = names.nextInt(smax-smin)+smin;
Steal = names.nextInt(smax-smin)+smin;
Stamina = names.nextInt(smax-smin)+smin;
PlayerObject.createPlayerEntry(teams[5], "w", players[5], cRange, mRange, tRange, Freethrow, Pass, Def_rebound, Off_rebound, Block, Steal, Stamina);
fnum = names.nextInt(max-min) + min;
snum = names.nextInt(max-min) + min;
players[0] = first_names[fnum] + " " + last_names[snum];
cRange = names.nextInt(smax-smin)+smin;
mRange = names.nextInt(smax-smin)+smin;
tRange = names.nextInt(smax-smin)+smin;
Freethrow = names.nextInt(smax-smin)+smin;
Pass = names.nextInt(smax-smin)+smin;
Def_rebound = names.nextInt(smax-smin)+smin;
Off_rebound = names.nextInt(smax-smin)+smin;
Block = names.nextInt(smax-smin)+smin;
Steal = names.nextInt(smax-smin)+smin;
Stamina = names.nextInt(smax-smin)+smin;
PlayerObject.createPlayerEntry(teams[6], "w", players[6], cRange, mRange, tRange, Freethrow, Pass, Def_rebound, Off_rebound, Block, Steal, Stamina);
fnum = names.nextInt(max-min) + min;
snum = names.nextInt(max-min) + min;
players[0] = first_names[fnum] + " " + last_names[snum];
cRange = names.nextInt(smax-smin)+smin;
mRange = names.nextInt(smax-smin)+smin;
tRange = names.nextInt(smax-smin)+smin;
Freethrow = names.nextInt(smax-smin)+smin;
Pass = names.nextInt(smax-smin)+smin;
Def_rebound = names.nextInt(smax-smin)+smin;
Off_rebound = names.nextInt(smax-smin)+smin;
Block = names.nextInt(smax-smin)+smin;
Steal = names.nextInt(smax-smin)+smin;
Stamina = names.nextInt(smax-smin)+smin;
PlayerObject.createPlayerEntry(teams[7], "w", players[7], cRange, mRange, tRange, Freethrow, Pass, Def_rebound, Off_rebound, Block, Steal, Stamina);
fnum = names.nextInt(max-min) + min;
snum = names.nextInt(max-min) + min;
players[0] = first_names[fnum] + " " + last_names[snum];
cRange = names.nextInt(smax-smin)+smin;
mRange = names.nextInt(smax-smin)+smin;
tRange = names.nextInt(smax-smin)+smin;
Freethrow = names.nextInt(smax-smin)+smin;
Pass = names.nextInt(smax-smin)+smin;
Def_rebound = names.nextInt(smax-smin)+smin;
Off_rebound = names.nextInt(smax-smin)+smin;
Block = names.nextInt(smax-smin)+smin;
Steal = names.nextInt(smax-smin)+smin;
Stamina = names.nextInt(smax-smin)+smin;
PlayerObject.createPlayerEntry(teams[8], "w", players[8], cRange, mRange, tRange, Freethrow, Pass, Def_rebound, Off_rebound, Block, Steal, Stamina);
fnum = names.nextInt(max-min) + min;
snum = names.nextInt(max-min) + min;
players[0] = first_names[fnum] + " " + last_names[snum];
cRange = names.nextInt(smax-smin)+smin;
mRange = names.nextInt(smax-smin)+smin;
tRange = names.nextInt(smax-smin)+smin;
Freethrow = names.nextInt(smax-smin)+smin;
Pass = names.nextInt(smax-smin)+smin;
Def_rebound = names.nextInt(smax-smin)+smin;
Off_rebound = names.nextInt(smax-smin)+smin;
Block = names.nextInt(smax-smin)+smin;
Steal = names.nextInt(smax-smin)+smin;
Stamina = names.nextInt(smax-smin)+smin;
PlayerObject.createPlayerEntry(teams[9], "w", players[9], cRange, mRange, tRange, Freethrow, Pass, Def_rebound, Off_rebound, Block, Steal, Stamina);
fnum = names.nextInt(max-min) + min;
snum = names.nextInt(max-min) + min;
players[0] = first_names[fnum] + " " + last_names[snum];
cRange = names.nextInt(smax-smin)+smin;
mRange = names.nextInt(smax-smin)+smin;
tRange = names.nextInt(smax-smin)+smin;
Freethrow = names.nextInt(smax-smin)+smin;
Pass = names.nextInt(smax-smin)+smin;
Def_rebound = names.nextInt(smax-smin)+smin;
Off_rebound = names.nextInt(smax-smin)+smin;
Block = names.nextInt(smax-smin)+smin;
Steal = names.nextInt(smax-smin)+smin;
Stamina = names.nextInt(smax-smin)+smin;
PlayerObject.createPlayerEntry(teams[10], "w", players[10], cRange, mRange, tRange, Freethrow, Pass, Def_rebound, Off_rebound, Block, Steal, Stamina);
fnum = names.nextInt(max-min) + min;
snum = names.nextInt(max-min) + min;
players[0] = first_names[fnum] + " " + last_names[snum];
cRange = names.nextInt(smax-smin)+smin;
mRange = names.nextInt(smax-smin)+smin;
tRange = names.nextInt(smax-smin)+smin;
Freethrow = names.nextInt(smax-smin)+smin;
Pass = names.nextInt(smax-smin)+smin;
Def_rebound = names.nextInt(smax-smin)+smin;
Off_rebound = names.nextInt(smax-smin)+smin;
Block = names.nextInt(smax-smin)+smin;
Steal = names.nextInt(smax-smin)+smin;
Stamina = names.nextInt(smax-smin)+smin;
PlayerObject.createPlayerEntry(teams[11], "w", players[11], cRange, mRange, tRange, Freethrow, Pass, Def_rebound, Off_rebound, Block, Steal, Stamina);
fnum = names.nextInt(max-min) + min;
snum = names.nextInt(max-min) + min;
players[0] = first_names[fnum] + " " + last_names[snum];
cRange = names.nextInt(smax-smin)+smin;
mRange = names.nextInt(smax-smin)+smin;
tRange = names.nextInt(smax-smin)+smin;
Freethrow = names.nextInt(smax-smin)+smin;
Pass = names.nextInt(smax-smin)+smin;
Def_rebound = names.nextInt(smax-smin)+smin;
Off_rebound = names.nextInt(smax-smin)+smin;
Block = names.nextInt(smax-smin)+smin;
Steal = names.nextInt(smax-smin)+smin;
Stamina = names.nextInt(smax-smin)+smin;
PlayerObject.createPlayerEntry(teams[12], "w", players[12], cRange, mRange, tRange, Freethrow, Pass, Def_rebound, Off_rebound, Block, Steal, Stamina);
fnum = names.nextInt(max-min) + min;
snum = names.nextInt(max-min) + min;
players[0] = first_names[fnum] + " " + last_names[snum];
cRange = names.nextInt(smax-smin)+smin;
mRange = names.nextInt(smax-smin)+smin;
tRange = names.nextInt(smax-smin)+smin;
Freethrow = names.nextInt(smax-smin)+smin;
Pass = names.nextInt(smax-smin)+smin;
Def_rebound = names.nextInt(smax-smin)+smin;
Off_rebound = names.nextInt(smax-smin)+smin;
Block = names.nextInt(smax-smin)+smin;
Steal = names.nextInt(smax-smin)+smin;
Stamina = names.nextInt(smax-smin)+smin;
PlayerObject.createPlayerEntry(teams[13], "w", players[13], cRange, mRange, tRange, Freethrow, Pass, Def_rebound, Off_rebound, Block, Steal, Stamina);
fnum = names.nextInt(max-min) + min;
snum = names.nextInt(max-min) + min;
players[0] = first_names[fnum] + " " + last_names[snum];
cRange = names.nextInt(smax-smin)+smin;
mRange = names.nextInt(smax-smin)+smin;
tRange = names.nextInt(smax-smin)+smin;
Freethrow = names.nextInt(smax-smin)+smin;
Pass = names.nextInt(smax-smin)+smin;
Def_rebound = names.nextInt(smax-smin)+smin;
Off_rebound = names.nextInt(smax-smin)+smin;
Block = names.nextInt(smax-smin)+smin;
Steal = names.nextInt(smax-smin)+smin;
Stamina = names.nextInt(smax-smin)+smin;
PlayerObject.createPlayerEntry(teams[14], "w", players[14], cRange, mRange, tRange, Freethrow, Pass, Def_rebound, Off_rebound, Block, Steal, Stamina);
fnum = names.nextInt(max-min) + min;
snum = names.nextInt(max-min) + min;
players[0] = first_names[fnum] + " " + last_names[snum];
cRange = names.nextInt(smax-smin)+smin;
mRange = names.nextInt(smax-smin)+smin;
tRange = names.nextInt(smax-smin)+smin;
Freethrow = names.nextInt(smax-smin)+smin;
Pass = names.nextInt(smax-smin)+smin;
Def_rebound = names.nextInt(smax-smin)+smin;
Off_rebound = names.nextInt(smax-smin)+smin;
Block = names.nextInt(smax-smin)+smin;
Steal = names.nextInt(smax-smin)+smin;
Stamina = names.nextInt(smax-smin)+smin;
PlayerObject.createPlayerEntry(teams[15], "w", players[15], cRange, mRange, tRange, Freethrow, Pass, Def_rebound, Off_rebound, Block, Steal, Stamina);
}
}
}
package ent.com;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class SetSql{
String saveExtra=null;
public static final String KEY_ROWID = "_id";
public static final String KEY_SAVE = "save_name";
public static final String KEY_STADIUM = "stadium_size";
public static final String KEY_FINANCE = "total_money";
private static String DATABASE_NAME = null;
private static final String DATABASE_TABLE = "save_data";
private static final int DATABASE_VERSION = 1;
private static final String PLAYERS_TABLE = "player_data";
public static final String ROWID = "_id";
public static final String TEAM = "team";
public static final String LOCATION = "location";
public static final String PLAYER = "player_name";
public static final String CRANGE = "close_range";
public static final String MRANGE = "mid_range";
public static final String TRANGE = "three_range";
public static final String FREETHROW = "free_throw";
public static final String PASS = "pass";
public static final String DEF_REBOUND = "def_rebound";
public static final String OFF_REBOUND = "off_rebound";
public static final String BLOCK = "block";
public static final String STEAL = "steal";
public static final String STAMINA = "stamina";
private DbHelper ourHelper;
private final Context ourContext;
private SQLiteDatabase ourDatabase;
private static class DbHelper extends SQLiteOpenHelper{
public DbHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
//userdata db
db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" +
KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
KEY_SAVE + " TEXT NOT NULL, " +
KEY_STADIUM + " INTEGER NOT NULL, " +
KEY_FINANCE + " DOUBLE NOT NULL);");
//players data db
db.execSQL("CREATE TABLE " + PLAYERS_TABLE + " (" +
ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
TEAM + " TEXT NOT NULL, " +
LOCATION + " TEXT NOT NULL, " +
PLAYER + " TEXT NOT NULL, " +
CRANGE + " INTEGER NOT NULL, " +
MRANGE + " INTEGER NOT NULL, " +
TRANGE + " INTEGER NOT NULL, " +
FREETHROW + " INTEGER NOT NULL, " +
PASS + " INTEGER NOT NULL, " +
DEF_REBOUND + " INTEGER NOT NULL, " +
OFF_REBOUND + " INTEGER NOT NULL, " +
BLOCK + " INTEGER NOT NULL, " +
STEAL + " INTEGER NOT NULL, " +
STAMINA + " INTEGER NOT NULL);");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
db.execSQL("DROP TABLE IF EXISTS " + PLAYERS_TABLE);
onCreate(db);
}
}
public SetSql(Context c){
ourContext = c;
}
public SetSql open(){
ourHelper = new DbHelper(ourContext);
ourDatabase = ourHelper.getWritableDatabase();
return this;
}
public void close(){
ourHelper.close();
}
public void start(String num){
saveExtra = num;
DATABASE_NAME = saveExtra;
}
public long createEntry(String value, int seats, int money, String players) {
ContentValues cv = new ContentValues();
cv.put(KEY_SAVE, value);
cv.put(KEY_STADIUM, seats);
cv.put(KEY_FINANCE, money);
return ourDatabase.insert(DATABASE_TABLE, null, cv);
}
public String getdata() {
String[] columns = new String[]{KEY_ROWID, KEY_SAVE, KEY_STADIUM, KEY_FINANCE};
Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);
String result = "";
int iRow = c.getColumnIndex(KEY_ROWID);
int iSave = c.getColumnIndex(KEY_SAVE);
int iSeats = c.getColumnIndex(KEY_STADIUM);
int iMoney = c.getColumnIndex(KEY_FINANCE);
for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
result = result + c.getString(iRow) + "-" + c.getString(iSave) + "-" + c.getString(iSeats) + "-" + c.getString(iMoney) + "\n";
}
return result;
}
public long createPlayerEntry(String team, String Location, String Player, int cRange, int mRange, int tRange, int Freethrow, int Pass, int Def_rebound, int Off_rebound, int Block, int Steal, int Stamina) {
ContentValues cv = new ContentValues();
cv.put(TEAM, team);
cv.put(LOCATION, Location);
cv.put(PLAYER, Player);
cv.put(CRANGE, cRange);
cv.put(MRANGE, mRange);
cv.put(TRANGE, tRange);
cv.put(FREETHROW, Freethrow);
cv.put(PASS, Pass);
cv.put(DEF_REBOUND, Def_rebound);
cv.put(OFF_REBOUND, Off_rebound);
cv.put(BLOCK, Block);
cv.put(STEAL, Steal);
cv.put(STAMINA, Stamina);
return ourDatabase.insert(PLAYERS_TABLE, null, cv);
}
public String getplayerdata() {
String[] columns = new String[]{ROWID, TEAM, LOCATION, PLAYER, CRANGE, MRANGE, TRANGE, FREETHROW, PASS, DEF_REBOUND, OFF_REBOUND, BLOCK, STEAL, STAMINA};
Cursor c = ourDatabase.query(PLAYERS_TABLE, columns, null, null, null, null, null);
String result = "";
int iRow = c.getColumnIndex(ROWID);
int iTeam = c.getColumnIndex(TEAM);
int iLocation = c.getColumnIndex(LOCATION);
int iPlayer = c.getColumnIndex(PLAYER);
int iCrange = c.getColumnIndex(CRANGE);
int iMrange = c.getColumnIndex(MRANGE);
int iTrange = c.getColumnIndex(TRANGE);
int iFreethrow = c.getColumnIndex(FREETHROW);
int iPass = c.getColumnIndex(PASS);
int iDef_rebound = c.getColumnIndex(DEF_REBOUND);
int iOff_rebound = c.getColumnIndex(OFF_REBOUND);
int iBlock = c.getColumnIndex(BLOCK);
int iSteal = c.getColumnIndex(STEAL);
int iStamina = c.getColumnIndex(STAMINA);
for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
result = result + c.getString(iRow) + "-" + c.getString(iTeam) + "-" + c.getString(iLocation) + "-" + c.getString(iPlayer) + "-" + c.getString(iCrange) + "-" + c.getString(iMrange) + "-" +c.getString(iTrange) + "-" +c.getString(iFreethrow) + "-" +c.getString(iPass) + "-" +c.getString(iDef_rebound) + "-" +c.getString(iOff_rebound) + "-" +c.getString(iBlock) + "-" +c.getString(iSteal) + "-" +c.getString(iStamina) + "-" +"\n";
}
return result;
}
}
答案 0 :(得分:2)
我认为west_teams有9个成员,将被编入0到8的索引。但是你的随机数可能是9,给你越界错误。