메인은 TimeAtivity 이고 메인이실행될때 SoundPlayer 객체생성해서 SQLite.selectMemo 메서드를 호출하려고하는데(초기값셋팅하려구요) 자꾸 널포인트익셉션 오류가 납니다
selectMemo 메서드의 Cursor c = mDb.rawQuery("SELECT memo FROM daily_memo WHERE _id = '"+id+"'", null);
부분만 주석처리해주면 강제종료가 되지않던데. select문은 sqlite3 로 실행했을때 결과값이 나오니까 문제없는거같구
기초적인 실수를 하고있는것 같은데 어디서 문제인지 잘 모르겠습니다 ㅠ
로그정보도 올리려고했는데 로그를 텍스트로 변환하는법을 몰라서 못올렸습니다
다음질문부터는 꼭 로그정보도 같이 올리겠습니다
제발 알려주세요! ㅜ
[code]
public class TimeActivity extends Activity {
SoundPlayer sp;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.timer);
sp = new SoundPlayer();
}
}
public class SoundPlayer {
private SQLite db;
private MediaPlayer mp;
public String beep;
public SoundPlayer(){
db = new SQLite(null);
mp = new MediaPlayer();
beep = db.selectMemo("1");
}
}
public class SQLite extends SQLiteOpenHelper
{
public SQLite(Context c) {
super(c, DB, null, DB_VERSION);
}
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_TABLE);
}
// 존재하는 데이터베이스로 정의하고있는 버전이 다를 때
public void onUpgrade(SQLiteDatabase db,
int oldVersion, int newVersion) {
Log.w(TAG,
"Version mismatch :" + oldVersion +
" to " + newVersion );
db.execSQL(DROP_TABLE);
onCreate(db);
}
// 데이터베이스 파일 이름
static final String DB="daily_memo.db";
// 테이블 이름
static final String TABLE = "daily_memo";
// 참고 열 이름
static final String MEMO="memo";
// 데이터베이스 버전
static final int DB_VERSION=1;
// 테이블 생성 SQL
static final String CREATE_TABLE =
"create table daily_memo (" +
"_id integer primary key autoincrement, " +
"memo text not null );";
// 테이블 삭제 SQL
static final String DROP_TABLE =
"drop table daily_memo;";
static final String TAG = "HelloSQLiteActivity";
private SQLiteDatabase mDb;
// 지정된 노트를 추가하여 ID를 반환
public void addMemo(String memo) { //addMemo 메서드 선언
ContentValues values = new ContentValues();
values.put(MEMO, memo);
mDb.insert(TABLE, null, values);
}
// 지정된 ID의 행 삭제
public void deleteMemo(String id) {
mDb.delete(TABLE, "_id = ?", new String[] { id });
}
// 검색문
public String selectMemo(String id) {
mDb = this.getReadableDatabase();
Cursor c = mDb.rawQuery("SELECT memo FROM daily_memo WHERE _id = '"+id+"'", null);
String a = c.getString(1);
return a;
}
// 지정된 ID 줄 메모 업데이트
public void setMemo(String id, String memo) { //setMemo 메서드 선언
try {
mDb = this.getWritableDatabase();
} catch (SQLiteException e) {
// 디스크 전체에서 데이터를 쓸 수없는 경우
Log.e(TAG,e.toString());
mDb = this.getReadableDatabase();
}
//업데이트 값 설정
ContentValues values = new ContentValues();
values.put(MEMO, memo);
// 행을 업데이트
mDb.update(TABLE, values, "_id = ?", new String[] { id });
}
}
[/code]