我从我的 logcat 中收到此错误。
03-19 08:41:48.174: E/Database(271): Error inserting height=53.0 status=OBESE bmi=38.290850836596654 contact_num=00000000000 address=usa age=21 gender=female weight_client=153.0 full_name=claire
03-19 08:41:48.174: E/Database(271): android.database.sqlite.SQLiteException: table client has no column named height: , while compiling: INSERT INTO client(height, status, bmi, contact_num, address, age, gender, weight_client, full_name) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?);
当我使用模拟器时,会发生这种情况。但是当我在我的设备上尝试时,数据插入似乎没有问题。我很困惑为什么会发生这种情况。有人可以向我解释一下吗?
此外,这是我DBAdapter
和我的代码,ViewClient.class
它可能有助于查明问题所在。
我的代码DBAdapter
:
public static final String TABLE_NAME = "client";
public static final String CLIENT_ID = "client_id";
public static final String FULLNAME = "full_name";
public static final String GENDER = "gender";
public static final String ADDRESS = "address";
public static final String AGE = "age";
public static final String CONTACT_NUM = "contact_num";
public static final String HEIGHT = "height";
public static final String WEIGHT = "weight_client";
public static final String BMI = "bmi";
public static final String STATUS = "status";
String sq_clients = "CREATE TABLE " + TABLE_NAME +
"(" + CLIENT_ID + " integer primary key autoincrement, " +
FULLNAME + " text not null, " +
GENDER + " text not null, " +
ADDRESS + " text not null, " +
AGE + " integer not null, " +
CONTACT_NUM + " text not null, " +
HEIGHT + " integer not null, " +
WEIGHT + " integer not null, " +
BMI + " integer not null, " +
STATUS + " text not null);";
ViewClient.java:
package com.example.********;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class DatabaseViewClient extends Activity {
private EditText fullname;
private EditText address_client;
private EditText age_client;
private EditText gender;
private EditText contactNum_client;
private EditText height_client;
private EditText weight_client;
private Button btnSaveCustomer;
int current_client_id;
String current_client_fullname;
String current_client_address;
String current_client_contactnum;
String current_client_height;
String current_client_weight;
String current_client_gender;
int current_client_age;
String current_client_bmi, current_client_status;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.addclient);
fullname = (EditText) findViewById(R.id.fullname);
gender = (EditText) findViewById(R.id.gender);
age_client = (EditText) findViewById(R.id.age_client);
address_client = (EditText) findViewById(R.id.address_client);
contactNum_client = (EditText) findViewById(R.id.contactNum_client);
height_client = (EditText) findViewById(R.id.height_client);
weight_client = (EditText) findViewById(R.id.weight_client);
btnSaveCustomer = (Button) findViewById(R.id.save);
Bundle extras = getIntent().getExtras();
current_client_id = extras.getInt("CLIENT_ID");
current_client_fullname = extras.getString("FULLNAME");
current_client_gender = extras.getString("GENDER");
current_client_age = extras.getInt("AGE");
current_client_address = extras.getString("ADDRESS");
current_client_contactnum = extras.getString("CONTACT_NUM");
current_client_height = extras.getString("HEIGHT");
current_client_weight = extras.getString("WEIGHT");
current_client_bmi = extras.getString("BMI");
current_client_status = extras.getString("STATUS");
fullname.setText(current_client_fullname);
gender.setText(current_client_gender);
address_client.setText(current_client_address);
contactNum_client.setText(current_client_contactnum);
height_client.setText(current_client_height);
weight_client.setText(current_client_weight);
fullname.setKeyListener(null);
gender.setKeyListener(null);
age_client.setKeyListener(null);
address_client.setKeyListener(null);
contactNum_client.setKeyListener(null);
height_client.setKeyListener(null);
weight_client.setKeyListener(null);
btnSaveCustomer.setVisibility(View.GONE);
}
}