1

Использование Android Studio 2,0Получение IOException без сообщений об ошибках Android

Не получив выход для

Log.v(LOG_TAG, "Response Code" + urlConnection.getResponseCode()); 
Log.v(LOG_TAG, "Error Stream" + urlConnection.getErrorStream()); 
Log.v(LOG_TAG, "Request Method" + urlConnection.getRequestMethod());  

с использованием Встроенный URI в браузере дает мне правильный результат.

до urlConnection.connect(); вызов метода getRequestMethod() дает мне имя метода GET.

код

try { 
    // Construct the URL for the OpenWeatherMap query 
    // Possible parameters are avaiable at OWM's forecast API page, at 
    // http://openweathermap.org/API#forecast 
    final String FORECAST_BASE_URL = "http://api.openweathermap.org/data/2.5/forecast/daily?"; 
    final String QUERY_PARAM = "q"; 
    final String FORMAT_PARAM = "mode"; 
    final String UNITS_PARAM = "units"; 
    final String DAYS_PARAM = "cnt"; 
    final String APPID_PARAM = "APPID"; 

    Uri builtUri = Uri 
      .parse(FORECAST_BASE_URL) 
      .buildUpon() 
      .appendQueryParameter(QUERY_PARAM, params[0]) 
      .appendQueryParameter(FORMAT_PARAM, format) 
      .appendQueryParameter(UNITS_PARAM, units) 
      .appendQueryParameter(DAYS_PARAM, Integer.toString(numDays)) 
      .appendQueryParameter(APPID_PARAM, 
        BuildConfig.OPEN_WEATHER_MAP_API_KEY).build(); 

    URL url = new URL(builtUri.toString()); 

    Log.v(LOG_TAG, "Built URI " + builtUri.toString()); 

    // Create the request to OpenWeatherMap, and open the connection 
    urlConnection = (HttpURLConnection) url.openConnection(); 
    // urlConnection.setRequestMethod("GET"); 
    urlConnection.connect(); 
    Log.v(LOG_TAG, "Response Code" + urlConnection.getResponseCode()); 
    Log.v(LOG_TAG, "Error Stream" + urlConnection.getErrorStream()); 
    Log.v(LOG_TAG, "Request Method" + urlConnection.getRequestMethod()); 

    // Read the input stream into a String 
    // InputStream inputStream = urlConnection.getInputStream(); 
    InputStream inputStream; 
    if (urlConnection.getResponseCode() >= 400) { 
     inputStream = urlConnection.getErrorStream(); 
    } else { 
     inputStream = urlConnection.getInputStream(); 
    } 
    // Log.v(LOG_TAG, "Response Code" +urlConnection.getHeaderFields()); 

    StringBuffer buffer = new StringBuffer(); 
    if (inputStream == null) { 
     // Nothing to do. 
     return null; 
    } 
    reader = new BufferedReader(new InputStreamReader(inputStream)); 

    String line; 
    while ((line = reader.readLine()) != null) { 
     // Since it's JSON, adding a newline isn't necessary (it won't 
     // affect parsing) 
     // But it does make debugging a *lot* easier if you print out 
     // the completed 
     // buffer for debugging. 
     buffer.append(line + "\n"); 
    } 

    if (buffer.length() == 0) { 
     // Stream was empty. No point in parsing. 

     return null; 
    } 
    forecastJsonStr = buffer.toString(); 
    Log.v(LOG_TAG, "JSON Response " + forecastJsonStr); 
} catch (IOException e) { 
    Log.e(LOG_TAG, "Error", e); 
    // If the code didn't successfully get the weather data, there's no 
    // point in attemping 
    // to parse it. 
    return null; 
} finally { 
    if (urlConnection != null) { 
     urlConnection.disconnect(); 
    } 
    if (reader != null) { 
     try { 
      reader.close(); 
     } catch (final IOException e) { 
      Log.e(LOG_TAG, "Error closing stream", e); 
     } 
    } 
} 

Журнал ошибок

04-22 18: 42: 16,444 9011-9011/com.android.serverwarrior.sunshine Е/ViewRootImpl: sendUserActionEvent() MView == null

04-22 18: 42: 17.405 9011-9314/com.android.serverwarrior.sunshine E/FetchWeatherTask: ошибка

+0

разве вы не проглатываете исключение с этой линией? Log.e (LOG_TAG, «Ошибка», e); – raven

+0

сообщение об ошибке всегда находится в логарифме, если вы правильно настроили фильтры. Должно быть больше ... – Opiatefuchs

+0

@Opiatefuchs Я не использую фильтр на logcat. –

ответ

0

Не знаю, но, я подключаю телефон к сети Wi-Fi и снова отправляю запрос, и у меня есть JSON resposne.

Я подтвердил это, вне сети, я не получаю выход.

О

04-22 18: 42: 16,444 9011-9011/com.android.serverwarrior.sunshine Е/ViewRootImpl: sendUserActionEvent() MView == NULL

Это потому что устройство Samsung, что я получил от других сообщений об этой ошибке. Эта часть может быть проигнорирована.

+0

yep ... samsung device .... У меня также есть проблемы с samsung galaxy s3 .... у него есть своя жизнь и пытается вас раздражать ..... – Opiatefuchs

+0

@Opiatefuchs Очень плохо знать, что проблемы не новы, но еще не решены. –

+0

@Opiatefuchs пытается запустить Android Studio в качестве администратора, это действительно быстрее, чем обычно, это то, что я заметил во время этого, так как я потратил почти 6 часов на это. –