首先,讓我解釋一下,我清楚地知道這是什麼意思例外,請仔細閱讀問題,如果你要回答的問題。無法創建內螺紋處理程序尚未調用looper.prepare例外
我知道,當你試圖做一個網絡UI線程工作異常出現。我正在使用AsyncTask,但我正在做任何UI操作。
下面是從的AsyncTask代碼片斷在錯誤被拋出 注意AP和ADM被宣佈提前 它在提取器初始化該異常被拋出:
do{
try{
HttpPost request = new HttpPost(params[0]);
request.setHeader("Accept", "application/json");
request.setHeader("Content-type", "application/json");
aps.setLastSent(lastSent);
StringEntity filterEntity = new StringEntity(aps.TempParameter()); //Remember this TempParameter is temporary function
request.setEntity(filterEntity);
response = httpClient.execute(request);
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK){
Extracter extracter = new Extracter(response);
lastSent = extracter.extractLastSent();
adm.addDictionary(extracter.extractDictionary());
}
} catch (ClientProtocolException e) {
//TODO Handle problems..
builder.append("Client protocol exception");
} catch (IOException e) {
//TODO Handle problems..
builder.append(e.toString());
}
}while(lastSent != "done");
return adm.getAlarmObjectList();
線
Extracter extracter = new Extracter(response);
就是拋出異常。 下面是提取器類的代碼:
public class Extracter extends AlarmLoopTestActivity {
private JSONObject jo;
private JSONArray ja;
public Extracter(HttpResponse response){
StringBuilder builder = new StringBuilder();
HttpEntity entity = response.getEntity();
try {
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
String line;
while((line = reader.readLine())!= null){
builder.append(line);
}
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String json = builder.toString();
try {
jo = (JSONObject) new JSONTokener(json).nextValue();
ja = jo.getJSONArray("effectNamesDict");
} catch (JSONException e) {
jo = null;
e.printStackTrace();
}
}
我假設printingStackTrace不被認爲是UI事件。除此之外,我不知所措。我需要對此有新的看法。如果我需要進一步闡述,請告訴我。
什麼是'AlarmLoopTestActivity'?換句話說,它最初是什麼「擴展」? – Squonk
可能是這樣,它不應該延伸。 – SmashCode
但是,爲了回答你的問題,AlarmLoopTestActivity是主要的活動,而不是工作線程,我現在固定它,我敢打賭,這就是它。我無法相信我沒有注意到這一點。 – SmashCode