마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

DB에서 계속 NULL값만 받아옵니다.

0 추천
public class ListActivity extends Activity{

 private static String[] food = {"누룽지", "참치김치찌게", "카레라이스", "죽", "즉석떡볶이", "찜닭"};

 private DBManager dbm;
 String name, info, ingredients, calorie, time, process, tip;
 ArrayAdapter<String> adapter;
 ArrayList<String> foodlist;
 ListView list;
 EditText foodnameText;
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.bt1_activity);
  
  dbm = new DBManager(this);
  final SQLiteDatabase db = dbm.getWritableDatabase();
  
  foodnameText = (EditText)findViewById(R.id.foodname);
  
  foodlist = new ArrayList<String>();
  foodlist.addAll(Arrays.asList(food));
  
  adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, foodlist);
  
  list = (ListView)findViewById(R.id.list);
  list.setAdapter(adapter);
  
  Button addButton = (Button)findViewById(R.id.add);
  addButton.setOnClickListener(new View.OnClickListener(){
   @Override
   public void onClick(View v){

    foodlist.add(0, foodnameText.getText().toString());
    adapter.notifyDataSetChanged();

    
   }
  });  
  
  /* 리스트뷰 롱클릭시 삭제 */
  list.setOnItemLongClickListener(new OnItemLongClickListener() { 
   public boolean onItemLongClick(AdapterView<?> parent, View view,
     final int position, long id) {
    
    AlertDialog diaBox = new AlertDialog.Builder(ListActivity.this)
    .setTitle("Delete")
       .setMessage("Really Delete?")
       .setIcon(R.drawable.ic_launcher)
       .setPositiveButton("no", new DialogInterface.OnClickListener() {
     public void onClick(DialogInterface dialog, int whichButton) {
       foodlist.remove(position);
       list.clearChoices();
       adapter.notifyDataSetChanged();
     }
    })
    .setNegativeButton("yes", null)
    .create();
    diaBox.show();
    return false;
   }
  });
 
          
       list.setOnItemClickListener(new OnItemClickListener() {
               public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
             
             try {
             Cursor cursor = db.rawQuery("SELECT * FROM FoodDataBase  ", null);
             
             while (cursor.moveToNext()) {
                       //선택한 아이템과 커서의 위치가 일치할때 해당 _id값을  temp로 가져옴(아 이거땜에 디지는줄아랐네)
              if(cursor.getPosition() == position) {
             name = cursor.getString(cursor.getColumnIndex("Name"));  
             info = cursor.getString(cursor.getColumnIndex("Info"));
             ingredients = cursor.getString(cursor.getColumnIndex("Ingredients"));
             calorie = cursor.getString(cursor.getColumnIndex("Calorie"));
             time = cursor.getString(cursor.getColumnIndex("Time"));
             process = cursor.getString(cursor.getColumnIndex("Process"));
             tip = cursor.getString(cursor.getColumnIndex("Tip"));    
              }
             }
                  
                Intent intent =  new Intent(ListActivity.this, Food_Info.class);
                intent.putExtra("NAME", name);
                intent.putExtra("INFO", info);
                intent.putExtra("INGREDIENTS", ingredients);
                intent.putExtra("CALORIE", calorie);
                intent.putExtra("TIME", time);
                intent.putExtra("PROCESS", process);
                intent.putExtra("TIP", tip);
                
                startActivity(intent);
                

                cursor.close();
          
         }catch(SQLiteException e) {
          Toast toast = Toast.makeText(ListActivity.this, "예외처리  되었습니다.", Toast.LENGTH_LONG);
                toast.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL, 0, 0);
                toast.show();}       
        }
       });
}

계속 NULL값만 받아오는 이유를 모르겟습니다.

테이블 작성도 했고 데이터베이스 폴더안에 모셔놓기도 했습니다.

eucharis7 (140 포인트) 님이 2013년 12월 12일 질문
어떤 행동을할때 null이 나는지를 알려주셔야 편할텐데..

1개의 답변

0 추천

어디서 null 이나는지는 모르겠지만.. 혹시나 18번째 줄쪽에서 null 난다면 

DB 파일 정보를 못 불러와서 에러가 나는거 일수도 있겠네요 ... 

어디서 나는 에러인지는 모르니.. 그냥 추측.``.. 

Jibsi (340 포인트) 님이 2013년 12월 12일 답변
...