错误提示是这样的:
The method setRequestMethod(String) is undefined for the type Object
程序的代码是:
public static String doGet(String msg){
String result="";
String url=setParams(msg);
try {
java.net.URL urlNet=new java.net.URL(url);
HttpURLConnection conn= (HttpURLConnection) urlNet.openConnection();
((URLConnection) conn).setReadTimeout(5*1000);
((URLConnection) conn).setConnectTimeout(5*1000);
((Object) conn).setRequestMethod("GET");
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
你的方法就是get网址返回一个结果回来是吧,应该是conn强转失败吧!
the method setRequestMethod(String) is undefined for the type Object:Objct类型不存在这个setRequestMethod()方法
URLConnection对象(即conn)转换成了Object对象。
解决方式:conn.setRequestMethod("GET");,不用转换类型
api上是有这个方法的,clean project试试看