Stacktrace:
06-26 15:30:45.019 2960-2996/yonitheweatherapp.theweatherapp E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: yonitheweatherapp.theweatherapp, PID: 2960
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:309)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:116)
at org.json.JSONTokener.nextValue(JSONTokener.java:94)
at org.json.JSONObject.<init>(JSONObject.java:156)
at org.json.JSONObject.<init>(JSONObject.java:173)
at data.JSONWeatherParser.getWeather(JSONWeatherParser.java:22)
at yonitheweatherapp.theweatherapp.MainActivity$WeatherTask.doInBackground(MainActivity.java:66)
at yonitheweatherapp.theweatherapp.MainActivity$WeatherTask.doInBackground(MainActivity.java:60)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
06-26 15:30:45.780 2960-2999/yonitheweatherapp.theweatherapp E/Surface: getSlotFromBufferLocked: unknown buffer: 0xae4513f0
doInBackground():
private class WeatherTask extends AsyncTask<String, Void, Weather>{
@Override
protected Weather doInBackground(String... params) {
String data = ((new WeatherHttpClient()).getWeatherData(params[0]));
weather = JSONWeatherParser.getWeather(data);
return weather;
}
@Override
protected void onPostExecute(Weather weather) {
super.onPostExecute(weather);
}
WeatherHttpClient(): public class WeatherHttpClient {
public String getWeatherData(String place){
HttpURLConnection connection = null;
InputStream inputStream = null;
try {
connection = (HttpURLConnection) (new URL(Utils.BASE_URL + place)).openConnection();
connection.setRequestMethod("GET");
connection.setDoInput(true);
connection.setDoOutput(true);
connection.connect();
//read the response
StringBuffer stringBuffer = new StringBuffer();
inputStream = connection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String line = null;
while((line = bufferedReader.readLine()) != null){
stringBuffer.append(line + "rn");
}
inputStream.close();
connection.disconnect();
return stringBuffer.toString();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
Any help please? I couldnt find the correct solution by myself.
Aucun commentaire:
Enregistrer un commentaire