首先,让我解释一下,我很清楚这个例外的含义,如果您要回答,请仔细阅读问题。
我知道当您尝试在网络线程上执行UI工作时会出现异常。我正在使用AsyncTask,但我正在进行任何UI操作。
以下是AsyncTask代码中引发错误的代码段 注意事先声明aps和adm 它在Extracter初始化中抛出了异常:
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);
是引发异常的地方。 以下是Extracter类的代码:
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事件。除此之外,我不知所措。我需要重新审视这个问题。如果我需要进一步详细说明,请告诉我。
答案 0 :(得分:0)
你的Extracter
正在扩展一个类AlarmLoopTestActivity
来自名称这是一个Android活动,因此它可能有一些UI交互方法!