0

我从我的 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);
}
}
4

2 回答 2

0

HEIGHT + "整数不为空,"

而你正在做:插入高度= 53.0

所以我想这可能是原因

UPD - 我看到你的重量是整数并且没有问题,所以应该有所不同:)

于 2013-03-19T01:24:00.520 回答
0

如果它在设备上而不是在模拟器上工作,它就可以工作。这可能不是您想听到的,但模拟器出了名的错误和不一致。我自己也有类似的问题,模拟器和设备的行为不同——“解决方案”是不使用模拟器。

本质上,如果您的问题是“在模拟器 X 上,但在设备 Y 上”,或者只是“为什么 X 在模拟器上不起作用”,那么模拟器很可能是问题所在。无论如何,解决特定于模拟器的错误是没有用的。

于 2013-03-19T01:29:48.737 回答