Вылетает ошибка при открытии URL подключения
Есть код:
String site = "http://somesite...";
URL url = new URL(site);
HttpURLConnection urlCon = (HttpURLConnection) url.openConnection();
urlCon.setRequestMethod("GET");
urlCon.setReadTimeout(10000);
urlCon.connect();
reader = new BufferedReader(new InputStreamReader(urlCon.getInputStream()));
StringBuilder buf = new StringBuilder();
String line=null;
while ((line=reader.readLine()) != null) {
buf.append(line + "\n");
}
На строке "urlCon.openConnection" программа переходит к блоку try-catch методы OnClick класса AppCompatViewInflater:
public void onClick(@ NonNull View v) {
if (mResolvedMethod == null) {
resolveMethod(mHostView.getContext(), mMethodName);
}
try {
mResolvedMethod.invoke(mResolvedContext, v);
} catch (IllegalAccessException e) {
throw new IllegalStateException(
"Could not execute non-public method for android:onClick", e);
} catch (InvocationTargetException e) {
throw new IllegalStateException(
"Could not execute method for android:onClick", e);
}
}
И дальше выполняется строка
throw new IllegalStateException("Could not execute method for android:onClick", e);
И это приводит к перезапуску программы. Как можно исправить?