2015-07-10 24 views
1

我有一個在eclipse開發的類(在同一臺計算機上),我試圖把它帶到Android Studio。 Android Studio給我一個錯誤,它不能解決的符號HttpsURLConnection試圖在Android工作室中使用類HttpsURLConnection,得到一個錯誤,說不能解決的符號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

該類您正在尋找不存在的,至少在Android系統。 Android SDK提供的是java.net.HttpURLConnection。順便說一下,您真正​​必須考慮的事情是Android編程不像普通的Java,它有一些特殊的規則。要搜索的正確文檔位於Android SDK official Page中。

除此之外,您的錯誤可能是您在Eclipse中導入了您在Android Studio中不再使用的庫。

相關問題