0

我运行以下代码并获得Java.lang.StringOutOfBound Exception

   SQLiteDatabase sb;
     String g="o";
    String []gt={"0"};
     try {
        sb=SQLiteDatabase.openDatabase("data/data/com.example.datatestx/ma", null, SQLiteDatabase.CREATE_IF_NECESSARY);

        sb.execSQL("create table if not exists blac  (" + " phone text  , " + " ftime  text, " + " ttime text );  "    );

        sb.execSQL( "insert into blac(phone, ftime,ttime) values ('01741297133', '333333','33333' );"  );
        sb.execSQL( "insert into blac(phone, ftime,ttime) values ('01761233433', '777' ,'77777');"  );
        sb.execSQL( "insert into blac(phone, ftime,ttime) values ('01712333333', '999','33433' );"  );
        //Cursor c1 = sb.rawQuery( "select * from blac where phone=?", gt);
        String gb="33"; 
        String gh = "SELECT * FROM blac where( phone like '%"+gb+" ')"+"ORDER BY phone";
        Cursor c1 = sb.rawQuery( gh,null);
    if(c1.getCount()>0){

    c1.moveToFirst();
    do {
        g=g+c1.getString(c1.getColumnIndex("phone"));

    }while(c1.moveToNext());
    }  c1.close();
        sb.close();

         Toast.makeText(getApplicationContext(), "Success!"+g, Toast.LENGTH_LONG).show();   
    }
    catch (Exception e)
    {

    Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();     
    }

但是在运行代码之后.. o g的值没有改变,请这里的任何人帮助我。

4

1 回答 1

0

您想从“电话”列中获取字符串,但据我所知,您没有创建这样的列:

    g=g+c1.getString(c1.getColumnIndex("phone"));

如果您的列有字符串常量,那么您以错误的方式编写您的 execSQL:

    sb.execSQL("create table if not exists blac  (" + " phone text  , " + " ftime  text, " + " ttime text );  "    );

你必须这样写:

    sb.execSQL("create table if not exists blac  (" +  phone +" text  , " +  ftime +" text, " +  ttime +" text );  "    );
于 2013-01-17T13:31:32.433 回答