InyncTask android. 다른 클래스의 메소드를 호출 할 때 doInBackGround() 태스크에서 null과 같은 예외가 발생합니다. Android AsyncTask 예외가 null이 됨
심지어 하드 내가 가진 예외 전자입니다 (URL이 방법은, JSON은), protected JSONArray doInBackground(Void... arg0) {
try {
return rest.request(url, method, json); // <-- returns json array
} catch (Exception e) {
this.e = e;
}
return null; // <--- returning this null
}
다른 일들이처럼
private class doRequest extends AsyncTask<Void, JSONArray, JSONArray>
protected void onPostExecute(JSONArray data)
/*rest client class*/
public class AndrestClient {
// The client to use for requests
DefaultHttpClient client = new DefaultHttpClient();
public JSONArray request(String url, String method, String json) throws RESTException {
if (method.matches("GET")) {
return get(url);
} else if (method.matches("POST")) {
return post(url, json);
} else if (method.matches("PUT")) {
//return put(url, data);
} else if (method.matches("DELETE")) {
//return delete(url);
}
throw new RESTException("Error! Incorrect method provided: " + method);
}
public JSONArray get(String url) throws RESTException {
String jsonjr = "['Chanuthi','Damsith','Dunili','Isath','Minuka','Uvin','Vidath']";
JSONArray jsonAraay = null;
try {
jsonAraay = new JSONArray(jsonjr);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return jsonAraay;
}
}
작동하지 않는 rest.request 내부 코드 = null. 다른 모든 것들이 제대로 작동합니다. doInBackGround에서 결과를 하드 코딩 할 때 제대로 작동합니다. 또한 나머지 클라이언트 get 메서드는 정확한 것을 반환합니다.
우리가 당신을 도울 수 있도록 더 많은 코드를 제공하십시오. 또한 예외의 스택 추적을 게시하고 정확하게 어떤 행이 올지를 게시하십시오. –
'나머지'의 요청 메소드는 어디에 정의되어 있습니까? 또한, url, method 및 json은 어디에 정의되어 있습니까? – MiiinimalLogic
사실, 질문 텍스트와 코드 주석은 모순입니다. null의 예외를 얻는다면 코드 주석처럼 자연스럽게 null을 반환 할 수 없습니다. 그래서 어떤가? – MiiinimalLogic