0
我知道當異步任務,我們嘗試更新doInBackGround UI這個錯誤出現...無法創建內螺紋已不叫Looper.prepare(處理器),而更新數據庫
,但我不能能夠得到它我在做的地方。
我之間一個非常龐大而穩定在截至目前的代碼...
SaveThread saveThread = new SaveThread(....);
Thread thread = new Thread(saveThread);
thread.start();
class SaveThread implements Runnable {
...........
...........
@Override
public void run() {
list = saveMultiple(mContext, array);
}
}
}
API saveMultiple(背景下,陣列)
{
Places placeItem = new Places().InitFromJsonObject(context,item);
}
API InitFromJsonObject(背景下,項目內內);
{
new Offers(context, offer);
}
API優惠(背景下,報價)裏面----> API保存(上下文)---->
內保存API
{
new AsyncTask<Void,Void,Void>(){
@Override
protected Void doInBackground(Void... params) {
Long now = Long.valueOf(System.currentTimeMillis());
if(context != null){
Cursor cursor = context.getContentResolver().query(CONTENT_URI, null, OFFER_ID + "=?", new String[]{offer_id}, null);
ContentValues contentValues = new ContentValues();
contentValues.put(OFFER_ID, offer_id);
int count = cursor.getCount();
if (count == 0) {
contentValues.put(CREATED_AT, now);
contentValues.put(UPDATED_AT, now);
context.getContentResolver().insert(CONTENT_URI, contentValues);
} else {
cursor.moveToFirst();
contentValues.put(UPDATED_AT, now);
context.getContentResolver().update(CONTENT_URI, contentValues, OFFER_ID + "=?", new String[]{offer_id});
}
cursor.close();
}
return null; //To change body of implemented methods use File | Settings | File Templates.
}
}.execute();
}
}
Error Logs are
java.lang.ExceptionInInitializerError
at com.y2cf.hoppr.dao.provider.models.Offers.save(Offers.java:118)
at com.y2cf.hoppr.dao.provider.models.Offers.save(Offers.java:113)
at com.y2cf.hoppr.dao.provider.models.Offers.<init>(Offers.java:90)
at com.y2cf.hoppr.dao.provider.models.Places.InitFromJsonObject(Places.java:528)
at com.y2cf.hoppr.dao.provider.models.Places.saveMultiple(Places.java:785)
at com.y2cf.hoppr.dao.provider.models.Places$SaveThread.run(Places.java:1571)
at java.lang.Thread.run(Thread.java:1019)
Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
at android.os.Handler.<init>(Handler.java:121)
at android.os.AsyncTask$InternalHandler.<init>(AsyncTask.java:421)
at android.os.AsyncTask$InternalHandler.<init>(AsyncTask.java:421)
at android.os.AsyncTask.<clinit>(AsyncTask.java:152)
... 7個
它執行異步任務時發生此錯誤,但我認爲在更新內容值時我沒有更新任何UI ..
我知道它是一個錯誤的編碼,因爲我們正在java本地線程內啓動異步任務......但爲什麼這個錯誤即將到來?
任何建議??