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 に答える