我正在尝试连接到android应用程序中的sunlight foundation api,但该应用程序一直崩溃

我正在尝试连接到android应用程序中的sunlight foundation api,但该应用程序一直崩溃,android,api,http,Android,Api,Http,给定一个邮政编码,我试图使用sunlight foundation api将该邮政编码返回给国会代表。现在,oncreate方法应该打印出邮政编码 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent(); String zipcode = intent.getStr

给定一个邮政编码,我试图使用sunlight foundation api将该邮政编码返回给国会代表。现在,oncreate方法应该打印出邮政编码

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent = getIntent();
        String zipcode = intent.getStringExtra(GetZipCode.EXTRA_MESSAGE);
        try {
            printCongressmen(zipcode);
        }
        catch(MalformedURLException e){

        }
        catch(IOException ex){

        }
        TextView textView = new TextView(this);
        textView.setTextSize(40);
        textView.setText(zipcode);
        setContentView(textView);
    }    
但是,在运行printCongressmen方法后崩溃后:

public void printCongressmen(String zipcode) throws IOException {
    String apikey = "6562c36e87ba41f6bc887104d1e82eb8";
    String baseURL = "https://congress.api.sunlightfoundation.com";
    String zipCodeAddition = "/legislators/locate?apikey="+apikey + "&zip=" + zipcode;
    String url = baseURL + zipCodeAddition;
    URL apiurl = new URL(url);
    HttpsURLConnection urlConnection = (HttpsURLConnection) apiurl.openConnection();
    try {
        InputStream in = new BufferedInputStream(urlConnection.getInputStream());
        int data = in.read();
        Log.v("INPUTSTREAM DATA", String.valueOf((char) data));
    }
    finally {
        urlConnection.disconnect();
    }
}

抱歉,如果我做了一些明显错误的事情,我是Android新手,一直在研究如何连接URL,但无法让它工作。应用程序只是关闭,没有显示邮政编码,也没有将任何内容记录到logcat

您正在尝试在主线程上进行网络调用。谢谢您!我不知道那是个问题。