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

_id 칼럼을 생성했는데 계속 못찾는다고 뜹니다

0 추천
package com.example.s1.pizza;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by s1 on 2015-12-10.
 */
public class DBHelper extends SQLiteOpenHelper {
    public DBHelper (Context context) {
        super(context, "Pizza.db", null, 1);
    }

    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE dic ( _id INTEGER PRIMARY KEY AUTOINCREMENT, "
        + "dough TEXT, topping TEXT, sidemenu TEXT, pay TEXT);");
    }

    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS dic;");
        onCreate(db);
    }
}

DB 생성하는 부분입니다

package com.example.s1.pizza;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RadioGroup;
import android.widget.Toast;


public class Order_Main extends Activity implements RadioGroup.OnCheckedChangeListener {

    DBHelper helper; //DB 도우미

    String dough = "";
    String topping = null; //DB에 저장할 변수

    RadioGroup dough_Group; //라디오 버튼 그룹

    CheckBox topping1;
    CheckBox topping2;
    CheckBox topping3;
    CheckBox topping4;
    CheckBox topping5; //체크박스 버튼

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.order_main);

        helper = new DBHelper(this);

        dough_Group = (RadioGroup)findViewById(R.id.dough);
        dough_Group.setOnCheckedChangeListener(this);

        topping1 = (CheckBox)findViewById(R.id.topping1);
        topping2 = (CheckBox)findViewById(R.id.topping2);
        topping3 = (CheckBox)findViewById(R.id.topping3);
        topping4 = (CheckBox)findViewById(R.id.topping4);
        topping5 = (CheckBox)findViewById(R.id.topping5);
    }

    public void onCheckedChanged (RadioGroup rg, int checked) {
        if(dough_Group.getCheckedRadioButtonId() == R.id.dough1) {
            dough = "팬";
        } else if(dough_Group.getCheckedRadioButtonId() == R.id.dough2) {
            dough = "치즈 크러스트";
        } else if(dough_Group.getCheckedRadioButtonId() == R.id.dough3) {
            dough = "리치 골드";
        }
    }

   public void SideNextBtnClick (View v) {
        BoxChecked(); //체크 되있는 체크 버튼을 확인해서 변수에 내용 저장

        SQLiteDatabase db;
        ContentValues row;

        db = helper.getWritableDatabase();
        Cursor cursor;
        cursor = db.rawQuery("SELECT _id FROM dic ORDER BY _id", null);

        int _id = 0; //주문번호
        while(cursor.moveToNext()) {
            _id = cursor.getInt(0);
        }

        _id++;

       row = new ContentValues();
       row.put("_id", _id);
       row.put("dough", dough);
       row.put("topping", topping);
       db.insert("dic", null, row);

        cursor.close();
        helper.close();

        Intent goside_in = new Intent(getApplicationContext(), Order_Side.class);
        startActivity(goside_in); //Order_Side로 이동
    }


    }

DB에 내용 추가하는 부분입니다

 

처음에 _id를 안넣었을때는 진행이 됬었습니다

근데 리스트뷰로 보여줄때 SimpleCursorAdapter를 사용할려면 _id가 필요하다고 하더라구요

그래서 추가했는데 계속

android.database.sqlite.SQLiteException: no such column: _id (code 1): , while compiling: SELECT _id FROM dic ORDER BY _id 라고 뜹니다

뭐가 잘못된건지 모르겠습니다 ㅠㅠㅠ

도와주세요

아니면 리스트뷰로 보여줄때 SimpleCursorAdapter 대신 쓸수있는거라도 알려주세요

징짱뀨우 (120 포인트) 님이 2015년 12월 12일 질문

1개의 답변

0 추천
_id가 없었을 때 되었다가 추가하니까 저런 에러메세지가 나온다면

아마도 그 전에 만들어진 테이블이 존재해서가 아닐까요?

앱을 아예 삭제했다가 다시 설치해보시는 게 먼저 확인해볼 사항인 것 같습니다.
cc1232 (35,280 포인트) 님이 2015년 12월 12일 답변
...