有人可以解释为什么以及如何解决此错误消息,我在编程或Android时在Eclipse中获取?Android Eclipse:HTTP无法解析为类型
HTTP不能被解析为一个类型
代码示例如下。
try {
// Call class "HTTP" passing an URL using Async "execute"
// Save returned string in "result"
String result = new HTTP().execute("http://domain.com/file.php?ID=1&R=T").get();
Log.i("EmonLog", "Result: "+result);
result = result.replaceAll("\"","");
TextView powerval = (TextView) findViewById(R.id.information_message);
powerval.setText("Result: " + result);
} catch (Exception e) {
Log.i("EmonLog", "Error: "+e);
}
的程序编译和完美的作品,但我得到这个错误,在HTTP下的红线,我想知道为什么,以及如何解决它。
编辑...添加了一些信息。这是execute调用的线程。
class HTTP extends AsyncTask<String, Void, String>
{
@Override
protected String doInBackground(String... params) {
String result = "";
try {
// Get the first parameter of the "params" which has been related to "String"
String urlstring = params[0];
// Log the string that contains the url
Log.i("EmonLog", "HTTP Connecting: "+urlstring);
// Convert the String into an actual URL
URL url = new URL(urlstring);
// Make the HTTP connection to the Internet
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
// Once the connection is done, try to store the information received into "reader"
try {
InputStream reader = new BufferedInputStream(urlConnection.getInputStream());
// Create a new String which will extract and contain the information received into the Buffered Input Stream
String text = "";
int i = 0;
while((i=reader.read())!=-1)
{
text += (char)i;
}
Log.i("EmonLog", "HTTP Response: "+text);
result = text;
} catch (Exception e) {
Log.i("EmonLog", "HTTP Exception: "+e);
}
finally {
Log.i("EmonLog", "HTTP Disconnecting");
urlConnection.disconnect();
}
} catch (Exception e) {
e.printStackTrace();
Log.i("EmonLog", "HTTP Exception: "+e);
}
return result;
}
}
我进口:
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
非常感谢您的帮助。
显示您的请求代码。 – 2014-09-29 07:13:25
我不明白。我在两个地方使用这个。 1)里面的按钮按这样的bt_button_HVAC25Vmax.setOnClickListener(新的View.OnClickListener(){(2)和这样的线程内public void run(){ – Serge 2014-09-29 07:15:02
我运行你的代码,一切工作正常。可能有些问题 – 2014-09-29 08:39:42