2013-03-19 23 views
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的代码,这可能有助于明确问题的出处。

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:从我DBAdapter

代码

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); 
} 
} 

回答

0

HEIGHT + “整数不为空,”

而且you're做:将高度= 53.0

所以我想这可能是原因

UPD - 我看到你有重量整数和鸵鸟政策有问题,所以应该是不同的东西呢:)

+0

我已经在我的查询中删除了“not null”部分,但它仍然提到了同样的问题。 – clairecaceres 2013-03-19 01:30:08

+0

我认为如果它在设备上工作,然后没有什么可以找到。如上所述,仿真器不是最好的工具。 – Roman 2013-03-19 01:32:17

0

如果它在设备上工作和不在模拟器上,它的工作原理。这可能不是你想听到的,但是模拟器是臭名昭着的并且不一致。我自己也有类似的问题,模拟器和设备的行为不同 - “解决方案”不使用模拟器。基本上,如果你的问题是沿着“在仿真器X上,但在设备Y上”,或者只是“为什么X不能在仿真器上工作”,那么模拟器很可能是问题所在。无论如何,解决特定于仿真器的错误是没有用的。

+0

感谢您的回复并分享了一些您的时间。我想我在面对那个错误后才感到恐慌。 – clairecaceres 2013-03-19 01:40:27