안드로이드 개발 질문/답변
(글 수 45,052)
public class findFood extends Activity {
FoodDBHelper mHelper;
EditText changeData;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mHelper = new FoodDBHelper(this);
Cursor c;
SQLiteDatabase db = mHelper.getWritableDatabase();
c = db.rawQuery("SELECT * FROM food", null);
startManagingCursor(c);
SimpleCursorAdapter adapter = null;
adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, c, new String[] {"name", "num"}, new int[] {android.R.id.text1, android.R.id.text2});
ListView list = (ListView)findViewById(R.id.DataList);
list.setAdapter(adapter);
changeData = (EditText)findViewById(R.id.InData);
changeData.addTextChangedListener(mWatch);
}
TextWatcher mWatch = new TextWatcher()
{
public void afterTextChanged(Editable s)
{
Toast.makeText(findFood.this, "검색 완료", Toast.LENGTH_SHORT).show();
}
public void beforeTextChanged(CharSequence s, int start, int count, int after)
{ }
public void onTextChanged(CharSequence s, int start, int before, int count)
{
String stn = s.toString();
try {
Display(stn);
} catch (Exception e) {}
}
private void Display(String ss) throws Exception{
// TODO Auto-generated method stub
mHelper = new FoodDBHelper(findFood.this);
Cursor c;
SQLiteDatabase db = mHelper.getWritableDatabase();
try{
Log.v("test", "Test1");
c = db.rawQuery("SELECT * FROM food WHRER " + ss, null);
Log.v("test", "Test2");
startManagingCursor(c);
Log.v("test", "Test3");
SimpleCursorAdapter adapter = null;
adapter = new SimpleCursorAdapter(findFood.this, android.R.layout.simple_list_item_2, c, new String[] {"name", "num"}, new int[] {android.R.id.text1, android.R.id.text2});
ListView list = (ListView)findViewById(R.id.DataList);
list.setAdapter(adapter);
}
catch(Exception e){
Toast.makeText(findFood.this, "검색 실패", Toast.LENGTH_SHORT).show();
}
}
};
}이렇게 소스를 짰는데 문제는 c = db.rawQuery("SELECT * FROM food WHRER " + ss, null);
이 코드에서 로그값이 멈추면서 예외처리 당해버리네요...
아무리 바꿔봐도 소용도 없고... 너무 힘든 나머지 다른분들께 도움을 받고 싶어서
이렇게 글을 올리게 되었습니다. 많은 지적좀 부탁드립니다.




님, where 다음의 비교문이 빠져있어요. 이를테면
c = db.rawQuery(
"SELECT * FROM food WHRER name='"+ ss+"'",null);이렇게 해야겠죠..
디버깅할 때 최소한 변수에 뭐가 담겨있는지 찍어보시는게.. 그래야 답변을 쉽게 할 수 있지 않겠습니까?
최소한 무슨 익셉션이라던가, 그리고 ADK 버전을 알려주셔야 답변드리는데 용이하겠네요..--;