试图在android studio中使用类HttpsURLConnection,收到错误说无法解析符号HttpsURLConnection

时间:2015-07-10 20:56:13

标签: android

我有一个在eclipse中开发的类(在同一台计算机上),我试图把它带到Android Studio。 Android Studio给我一个错误,它无法解析符号HttpsURLConnection

在甲骨文的网站上,据说这个班级在java.net.URLConnection,当我导入它时,该行是灰色的,说已经导入了。

代码:

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Date;

public class cBitTrex {
    static int test;



    /////////////////////////////////////////////////////////////////////
    // Run code to talk to server on a thread
    // Every onunce in a while code to tal to server will freex
    // WEcall thread methed run and then wait for thread to exit with a time out
    public class cThread extends Thread{
        String reply=null;
        String url;


        public void run()
        {
            String ireply;
            error="";
            ireply="";
            try {
                ireply="";
                URL myurl = new URL(url);
                System.out.println("Open thread connection");

                // This is where the error is               
                HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection();
                con.setConnectTimeout(15000);

                System.out.println("Get input thread stream");
                InputStream ins = con.getInputStream();
                System.out.println("Create reader");
                InputStreamReader isr = new InputStreamReader(ins);
                System.out.println("Creat buffer threadreader");
                BufferedReader in = new BufferedReader(isr);

                String inputLine;

                System.out.println("THREAD Read indata2");

                int t;
                while ((t= in.read()) != -1)
                {
                    ireply+=(char)t;;
                }

                System.out.println("finish Read indata");
            } catch (Exception e)
            {
                error=new String(e.getMessage());
                System.out.println("Exception in getting data from API server");
                reply=null;
            }

            // Set return valur at end of thread so if thread call tiimout we will not
            // get any data
            reply=ireply;
        }

    };
..
...
}

1 个答案:

答案 0 :(得分:1)

您要搜索的这个类不存在,至少在Android中是这样。 Android SDK提供的版本为Android SDK official Page。顺便说一句,你真正需要考虑的是Android的编程不仅仅是普通的Java,它有一些特殊的规则。要搜索的正确文档是位于{{3}}。

中的文档

除此之外,您的错误可能是您在Eclipse中导入了一个您在Android Studio中不再使用的库。