iOS를 하다가 안드로이드 프로젝트를 급하게 맡아서 열심히 배우며 하고있습니다...ㅠ
sqlite예제를 가져와서 가지고 있는 DB만 바꾸고, 해당 쿼리들만 바꿔서 돌려보니
에러가 나네요.. 로그를 보니
01-27 15:09:12.650: ERROR/AndroidRuntime(17094): Caused by: java.lang.IllegalArgumentException: column '_id' does not exist
디비는 캡쳐해서 이미지로 올렸습니다.
public static final String ROOT_DIR = "/data/data/com.romen.CancerAdvice/databases/";
ProductDBHelper mHelper;
public void setDB() {
File folder = new File(ROOT_DIR);
if(folder.exists()) {
}
else {
folder.mkdirs();
//Toast.makeText(this, "폴더생성", Toast.LENGTH_LONG).show();
}
AssetManager assetManager = getResources().getAssets();
File outfile = new File(ROOT_DIR+"a.sqlite"); //--폰에 위치할 경로
InputStream is = null;
FileOutputStream fo = null;
long filesize = 0;
try {
// --asset 폴더 및 복사할 DB 지정
is = assetManager.open("a.sqlite", AssetManager.ACCESS_BUFFER);
filesize = is.available(); //--사이즈 검증
// 파일이 없거나 패키지 폴더에 설치된 DB파일이 포함된 DB파일 보다 크기가 같지않을 경우 DB파일을 덮어 쓴다.
if (outfile.length() <= 0) {
byte[] tempdata = new byte[(int) filesize];
is.read(tempdata);
is.close();
outfile.createNewFile();
fo = new FileOutputStream(outfile);
fo.write(tempdata);
fo.close();
}
else
{
//Toast.makeText(this, "db있음", Toast.LENGTH_LONG).show();
}
} catch (IOException e) {
Toast.makeText(this, "db이동실패", Toast.LENGTH_LONG).show();
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
setDB();
super.onCreate(savedInstanceState);
TabHost mTab=getTabHost();
//ArrayAdapter<CharSequence> Adapter;
LayoutInflater inflater=LayoutInflater.from(this);
inflater.inflate(R.layout.main, mTab.getTabContentView(),true);
mTab.addTab(mTab.newTabSpec("tag")
.setIndicator("kkk")
.setContent(R.id.opt_stomach));
mHelper=new ProductDBHelper(this);
db=mHelper.getWritableDatabase();
cursor=db.rawQuery("Select * from laundry",null);
startManagingCursor(cursor);
//cursor.moveToLast();
//String str=cursor.getString(5);
//Toast.makeText(this,str, Toast.LENGTH_LONG).show();
ListView list=(ListView)findViewById(R.id.stomach_list);
AdapterStomach=new SimpleCursorAdapter(list.getContext(), R.layout.mylist, cursor,
new String[]{"m_name"},new int[]{R.id.text1});
list.setAdapter(AdapterStomach);
}
class ProductDBHelper extends SQLiteOpenHelper{
public ProductDBHelper(Context context) {
super(context, "a.sqlite", null, 1);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
}




커서 어댑터가 _id라는 이름의 column이 없으면 에러를 뱉습니다.
select * from laundry -> select ser_no _id, * from laundry로 바꿔보시는 건 어떨까요?