Запускаю приложение, все работает. Когда ввожу название города и нажимаю кнопку, приложение вылетает

package com.example.weather;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class MainActivity extends AppCompatActivity {
  private EditText cityname;
  private Button button1;
  private TextView textView2;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    cityname = findViewById(R.id.cityname);
    button1 = findViewById(R.id.button1);
    textView2 = findViewById(R.id.textView2);

    button1.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
        if (cityname.getText().toString().trim().equals(""))
          Toast.makeText(MainActivity.this, R.string.warning, Toast.LENGTH_LONG).show();
        else {
          String city = cityname.getText().toString();
          String key = "cba05fac32e986f325878b497331cfc8";
          String url = "https://api.openweathermap.org/data/2.5/weather?q=" + city + "&appid=" + key + "&units=metric+&lang=ru";
          new GerUrlData().execute(url);

        }
      }
    });

  }
  private class GerUrlData extends AsyncTask < String, String, String > {
    protected void onPreExecute() {
      super.onPreExecute();
      textView2.setText("Ожидайте...");
    }

    @Override
    protected String doInBackground(String...strings) {
      HttpURLConnection connection = null;
      BufferedReader reader = null;
      try {
        URL url = new URL(strings[0]);
        connection = (HttpURLConnection) url.openConnection();
        connection.connect();
        InputStream stream = connection.getInputStream();
        reader = new BufferedReader(new InputStreamReader(stream));
        StringBuffer buffer = new StringBuffer();
        String line = "";
        while ((line = reader.readLine()) != null)
          buffer.append(line).append("\n");
        return buffer.toString();


      } catch (MalformedURLException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      } finally {
        if (connection != null)
          connection.disconnect();
        try {
          if (reader != null)
            reader.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return null;
    }
    @SuppressLint("SetTextI18n")
    @Override
    protected void onPostExecute(String result) {
      super.onPostExecute(result);
      try {
        JSONObject jsonObject = new JSONObject(result);
        textView2.setText("Температура: " + jsonObject.getJSONObject("main").getDouble("temp"));

      } catch (JSONException e) {
        e.printStackTrace();
      }
    }
  }
}

Ошибки:

E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: com.example.weather, PID: 13416
java.lang.RuntimeException: An error occurred while executing doInBackground()
            at android.os.AsyncTask$4.done(AsyncTask.java:415)
            at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
            at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
            at java.util.concurrent.FutureTask.run(FutureTask.java:271)
            at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
            at java.lang.Thread.run(Thread.java:920)
         Caused by: java.lang.SecurityException: Permission denied (missing INTERNET permission?)
            at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:150)
            at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:103)
            at java.net.InetAddress.getAllByName(InetAddress.java:1152)
            at com.android.okhttp.Dns$1.lookup(Dns.java:41)
            at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:178)
            at com.android.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:144)
            at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:86)
            at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:176)
            at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:128)
            at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:97)
            at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:289)
            at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:232)
            at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:465)
            at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:131)
            at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.connect(DelegatingHttpsURLConnection.java:90)
            at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:30)
            at com.example.weather.MainActivity$GerUrlData.doInBackground(MainActivity.java:68)
            at com.example.weather.MainActivity$GerUrlData.doInBackground(MainActivity.java:55)
            at android.os.AsyncTask$3.call(AsyncTask.java:394)
            at java.util.concurrent.FutureTask.run(FutureTask.java:266)
            at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305) 
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
            at java.lang.Thread.run(Thread.java:920) 
         Caused by: android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
            at libcore.io.Linux.android_getaddrinfo(Native Method)
            at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:136)
            at libcore.io.BlockGuardOs.android_getaddrinfo(BlockGuardOs.java:221)
            at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:136)
            at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:135)
            at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:103) 
            at java.net.InetAddress.getAllByName(InetAddress.java:1152) 
            at com.android.okhttp.Dns$1.lookup(Dns.java:41) 
            at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:178) 
            at com.android.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:144) 
            at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:86) 
            at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:176) 
            at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:128) 
            at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:97) 
            at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:289) 
            at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:232) 
            at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:465) 
            at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:131) 
            at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.connect(DelegatingHttpsURLConnection.java:90) 
            at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:30) 
            at com.example.weather.MainActivity$GerUrlData.doInBackground(MainActivity.java:68) 
            at com.example.weather.MainActivity$GerUrlData.doInBackground(MainActivity.java:55) 
            at android.os.AsyncTask$3.call(AsyncTask.java:394) 
            at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
            at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305) 
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
            at java.lang.Thread.run(Thread.java:920) 
         Caused by: android.system.ErrnoException: android_getaddrinfo failed: EPERM (Operation not permitted)
            at libcore.io.Linux.android_getaddrinfo(Native Method) 
            at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:136) 
            at libcore.io.BlockGuardOs.android_getaddrinfo(BlockGuardOs.java:221) 
            at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:136) 
            at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:135) 
            at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:103) 
            at java.net.InetAddress.getAllByName(InetAddress.java:1152) 
            at com.android.okhttp.Dns$1.lookup(Dns.java:41) 
            at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:178) 
            at com.android.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:144) 
            at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:86) 
            at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:176) 
            at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:128) 
            at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:97) 
            at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:289) 
            at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:232) 
            at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:465) 
            at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:131) 
            at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.connect(DelegatingHttpsURLConnection.java:90) 
            at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:30) 
            at com.example.weather.MainActivity$GerUrlData.doInBackground(MainActivity.java:68) 
            at com.example.weather.MainActivity$GerUrlData.doInBackground(MainActivity.java:55) 
            at android.os.AsyncTask$3.call(AsyncTask.java:394) 
            at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
            at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305) 
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
            at java.lang.Thread.run(Thread.java:920)

Main activity:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout     
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:background="@color/white"
    tools:context=".MainActivity">

<TextView 
    android:id="@+id/textView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="50sp"
    android:fontFamily="@font/mouse_memoirs"
    android:text="@string/logo"
    android:textAlignment="center"
    android:textColor="@color/black"
    android:textSize="30sp" />

<EditText
    android:id="@+id/cityname"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/textView1"
    android:layout_marginHorizontal="50sp"
    android:layout_marginTop="100sp"
    android:backgroundTint="@color/black"
    android:ems="10"
    android:hint="@string/hint_cityname"
    android:inputType="textPersonName"
    android:minHeight="48dp"
    android:textColorHint="@color/black" />

<Button
    android:layout_width="match_parent" 
    android:id="@+id/button1"
    android:layout_height="wrap_content"
    android:layout_below="@+id/cityname"
    android:layout_marginTop="15sp"
    android:layout_marginHorizontal="30sp" 
    android:backgroundTint="@color/grey"
    android:text="@string/button1"
    android:textColor="@color/black"
    android:fontFamily="@font/mouse_memoirs" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/button1"
    android:layout_marginTop="50sp"
    android:fontFamily="@font/mouse_memoirs"
    android:textAlignment="center"
    android:textColorHint="@color/black"
    android:textSize="24sp" />

Ответы (0 шт):