有人可以解釋爲什麼以及如何解決此錯誤消息,我在編程或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