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