0
我是android编程新手。我已经创建了一个应用程序,可以填充数据并在表格中显示此数据。但是,我得到一个错误:错误:“必须从UI线程调用方法getText(),当前推断的线程是worker。”
下面几行Method getText() must be called from the UI Thread, currently inferred thread is worker
:
weight.getText() txtDate.getText() txtTime.getText()
在此代码:
@Override
protected Void doInBackground(Void... params) {
String w_value = weight.getText().toString();
String wdate = txtDate.getText().toString();
String wtime = txtTime.getText().toString();
// inserting data
sqlcon.open();
sqlcon.insertData(w_value, wdate, wtime);
BuildTable();
return null;
}
重量 - 显示数(27.6,5,0)
txtDate - 显示日期(20-09-2016,12-03-1988)
txtTime - 显示时间(15:16,1:06)
我insertData方法:
public void insertData(String weight, String date) {
ContentValues cv = new ContentValues();
cv.put(MyDbHelper.WEIGHT, weight);
cv.put(MyDbHelper.WEIGHT_DATE, String.valueOf(date));
cv.put(MyDbHelper.WEIGHT_TIME, new SimpleDateFormat("HH:mm").format(new Date()));
database.insert(MyDbHelper.TABLE_WEIGHT, null, cv);
}