gpt4 book ai didi

android - 尝试在 android studio 中使用类 HttpsURLConnection,收到一条错误消息,提示无法解析符号 HttpsURLConnection

转载 作者:行者123 更新时间:2023-11-30 02:01:52 26 4
gpt4 key购买 nike

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

在 Oracle 的网站上,据说该类在 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;
}

};
..
...
}

最佳答案

您搜索的这个类不存在,至少在 Android 中不存在。 Android SDK 提供的是java.net.HttpURLConnection。 .顺便说一句,您真正需要考虑的一点是,Android 编程与普通 Java 不同,它有一些特殊规则。要搜索的正确文档是位于 Android SDK official Page 中的文档。 .

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

关于android - 尝试在 android studio 中使用类 HttpsURLConnection,收到一条错误消息,提示无法解析符号 HttpsURLConnection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31350132/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com