我无法在SQLite数据库中存储数据

时间:2014-04-11 11:57:00

标签: java android

我正在尝试将数据存储到SQLite数据库中,请任何人帮我解决问题错误是order.addOrder(s,i)和order = new AdapterClass(this)带有错误add参数来匹配Adapterclass(Context,string )。

public class OrderScreen extends Activity implements OnClickListener   {
    TextView orderitem;
    EditText Quantity,devide_quanity;
     Button Place_Order,button_back;
     String tempstring;
     Integer i;
     String s;
     AdapterClass order = null;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.order_screen);

        orderitem =(TextView)findViewById(R.id.orderitem);
        Quantity =(EditText)findViewById(R.id.Quantity);
        order= new AdapterClass(this);

        s= getIntent().getStringExtra("order");
        String a[] = s.split("-");

        Place_Order = (Button)findViewById(R.id.Place_Order_btn);
        Place_Order.setOnClickListener(this);
      }

    @Override
    public void onClick(View v) 
    {
        tempstring=Quantity.getText().toString();

        i=Integer.parseInt(tempstring); 
        Toast.makeText(OrderScreen.this, s, Toast.LENGTH_LONG);
        //  adding the data 
        order.addOrder(s, i);
        //finish(); 
    }
}

//这是AdapterClass,在这行database.insert(“CUS_MENU”,null,ocv)参数显示错误,请帮助我任何人。     公共类AdapterClass     {         私有上下文;         私有SQLiteDatabase数据库;         CreateDB dbHelper;         private static String DATABASE_TABLE =“”;

    public AdapterClass(Context pcontext, String pDBTableName) 
    {
        // TODO Auto-generated constructor stub
        this.context = pcontext;
        this.DATABASE_TABLE = pDBTableName;
    }

    public AdapterClass Open() throws SQLException
    {
        dbHelper=new CreateDB(context);
        database=dbHelper.getWritableDatabase();
        return this;
    }


    // Split the sting into two parts
    public void addOrder(String s, int qty){

        ContentValues ocv = new ContentValues();
        String a[] = s.split("-");
        String price = a[1].replaceAll("[^0-9]", "");
        int total = Integer.parseInt(price)*qty;
        ocv.put("PRICE", price);
        ocv.put("NAME", a[0]);
        ocv.put("QTY", qty);
        ocv.put("TOTAL", total);
        //db=this.getWritableDatabase();
        database.insert("CUS_MENU",null , ocv);
        //database.close(); 
    }

    }

0 个答案:

没有答案