Windows7 64bit
AndroidStuido 1.5.1
『学習サイト』のサンプルを引用しつつ、文字を変えながらSQLiteの学習をしているのですが・・・・
同じように記述したつもりですが・・・・エラーが出されてしまいます。
原因がわかりません。オリジナルのサンプルならきれいに出力されるのです。
どなたか、ご指摘を頂けませんでしょうか?よろしくお願いします。
MainActivity.java
package testtesttest.tesutoapuri;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends AppCompatActivity {
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // open db ItemOpenHelper itemOpenHelper = new ItemOpenHelper(this); SQLiteDatabase db = itemOpenHelper.getWritableDatabase(); Cursor c = null; c = db.query( ItemContract.Personal.TABLE_NAME, null, // fields null, // where null, // where arg null, // groupBy null, // having null // order by );
//logcatで見えるようにしているみたいです。
Log.v("DB_TEST", "Count: " + c.getCount()); while(c.moveToNext()) { int id = c.getInt(c.getColumnIndex(ItemContract.Personal._ID)); String name = c.getString(c.getColumnIndex(ItemContract.Personal.COL_NAME)); int old = c.getInt(c.getColumnIndex(ItemContract.Personal.COL_OLD)); Log.v("DB_TEST", "id: " + id + " name: " + name + " old: " + old ); } c.close(); // close db db.close(); }
}
ItemOpenHelper.java
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class ItemOpenHelper extends SQLiteOpenHelper {
public static final String DB_NAME = "cccccc.db"; public static final int DB_VERSION = 1001; public static final String CREATE_TABLE = "create table aabbcc (" + "_ID integer primary key autoincrement, " + "name text," + "old integer)" ; public static final String INIT_TABLE = "insert into aabbcc(name, old) values" + "('aaaa', 1 ), " + "('bbbb', 10 ), " + "('cccc', 22 ) " ; public static final String DROP_TABLE = "drop table if exists aabbcc"; public ItemOpenHelper(Context c) { super(c, DB_NAME, null, DB_VERSION); } @Override public void onCreate(SQLiteDatabase db) { // create table db.execSQL(CREATE_TABLE); // init table db.execSQL(INIT_TABLE); } @Override public void onUpgrade(SQLiteDatabase db, int i, int ii) { db.execSQL(DROP_TABLE); onCreate(db); }
}
ItemContract.java
import android.provider.BaseColumns;
public final class ItemContract {
public ItemContract() { } public static abstract class Personal implements BaseColumns { public static final String TABLE_NAME = "aabbcc"; public static final String COL_NAME = "name"; public static final String COL_OLD = "old"; }
}
Logcatに表示されているエラー内容<Errorフィルタしてます>を下記に載せます。
02-19 20:57:55.918 979-2367/?
E/AudioFlinger: read failed: framesRead=-1
02-19 20:57:55.921 2447-2447/?
E/memtrack: Couldn't load memtrack module (No such file or directory)
02-19 20:57:55.921 2447-2447/?
E/android.os.Debug: failed to load memtrack module: -2
02-19 20:57:55.997 979-2367/?
E/AudioFlinger: read failed: framesRead=-1
02-19 20:57:56.005 1796-2365/?
E/AudioRecord-JNI: Error -4 during AudioRecord native read
02-19 20:57:56.402 2468-2468/?
E/CursorWindow: Failed to read row 0, column -1 from a CursorWindow which has 3 rows, 3 columns.
02-19 20:57:56.402 2468-2468/?
E/AndroidRuntime: FATAL EXCEPTION: main
<この間に>
02-19 20:57:57.109 968-1349/?
E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
02-19 20:57:59.991 1599-1599/?
E/NetworkScheduler.SchedulerReceiver: Invalid parameter app
02-19 20:57:59.991 1599-1599/?
E/NetworkScheduler.SchedulerReceiver: Invalid package name : Perhaps you didn't include a PendingIntent in the extras?
回答1件
あなたの回答
tips
プレビュー